Skip to content

Commit

Permalink
Added more tables
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaCappelletti94 committed Feb 8, 2024
1 parent f98fbc3 commit 4236afe
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
CREATE TABLE samples (
id SERIAL PRIMARY KEY,
taxon_id INTEGER NOT NULL REFERENCES taxons(id) ON DELETE CASCADE,
name VARCHAR(255) NOT NULL,
description VARCHAR(512) NOT NULL,
latitude DOUBLE PRECISION,
longitude DOUBLE PRECISION,
altitude DOUBLE PRECISION,
sample_type_id INTEGER NOT NULL REFERENCES sample_types(id) ON DELETE CASCADE,
derived_from INTEGER REFERENCES samples(id) ON DELETE SET NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,11 @@
-- and may be rented. As such it as two different columns one for the cost, its currency,
-- and a cost per day for renting and the current of the renting cost. An item may have
-- an expiration date and may be associated with one or more projects (which is tracked
-- in the item_projects table). An item type may define an item that has been manifactured,
-- such as a tube, a rack, a freezer, a microscope, etc. Additional item types may be more
-- organic such as edible products (bread, cheese, etc.). Some items may be instead collected
-- in nature such as rocks, plants, etc. The item_types table contains a name column to store
-- the name of the item type, a description column to store a description of the item type,
-- the created_at and updated_at columns to store the creation and last update time of the record,
-- plus who created and last updated the record. An item type may also have a manifacturer.
-- in the item_projects table).
CREATE TABLE item_types (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL UNIQUE,
description TEXT,
cost DECIMAL(10, 2) DEFAULT NULL,
currency VARCHAR(3) DEFAULT NULL,
cost_per_day DECIMAL(10, 2) DEFAULT NULL,
current_rental_cost DECIMAL(10, 2) DEFAULT NULL,
expiration_date DATE DEFAULT NULL,
manufacturer INTEGER REFERENCES organizations(id) DEFAULT NULL,
created_by INTEGER REFERENCES users(id),
updated_by INTEGER REFERENCES users(id),
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- This file should undo anything in `up.sql`
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- SQL defining the manufactured_item_types table.
-- A manufactured type is an item type that can be manufactured, sold, and bought. As such it
-- has a cost, its currency, and a cost per day for renting and the current of the renting
-- cost.
CREATE TABLE manufactured_item_types (
id SERIAL PRIMARY KEY,
item_type_id INTEGER REFERENCES item_types(id),
cost DECIMAL(10, 2) NOT NULL,
cost_per_day DECIMAL(10, 2) NOT NULL,
currency VARCHAR(3) NOT NULL,
manifacturer_id INTEGER REFERENCES organizations(id),
barcode VARCHAR(255) NOT NULL UNIQUE,
created_by INTEGER REFERENCES users(id),
updated_by INTEGER REFERENCES users(id),
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE expirable_item_types;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- SQL defining the expirable_item_types table.
-- Item types appearing in this table have an expiration date, meaning that
-- they have an interval of time associated to them after which they are no longer
-- valid. This table is used to enforce the expiration date of items of a certain type.
CREATE TABLE expirable_item_types (
id SERIAL PRIMARY KEY,
item_type_id INTEGER REFERENCES item_types(id),
expiration_interval INTERVAL NOT NULL,
created_by INTEGER REFERENCES users(id),
updated_by INTEGER REFERENCES users(id),
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

0 comments on commit 4236afe

Please sign in to comment.