diff --git a/web/backend/migrations/2024-01-24-233039_create_samples_table/up.sql b/web/backend/migrations/2024-01-24-233039_create_samples_table/up.sql index edb9da67..3c6b75a6 100644 --- a/web/backend/migrations/2024-01-24-233039_create_samples_table/up.sql +++ b/web/backend/migrations/2024-01-24-233039_create_samples_table/up.sql @@ -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, diff --git a/web/backend/migrations/2024-02-06-144814_create_laboratories_table/up.sql b/web/backend/migrations/2024-02-06-144814_create_laboratories_table/up.sql deleted file mode 100644 index cd66877a..00000000 --- a/web/backend/migrations/2024-02-06-144814_create_laboratories_table/up.sql +++ /dev/null @@ -1,15 +0,0 @@ --- SQL defining the laboratories table. --- A laboratory is a place where experiments are conducted. The laboratory table --- contains information about the laboratory, such as the name, description, and --- the organization that the laboratory belongs to. The created_at and updated_at --- columns are used to store the creation and last update time of the record. -CREATE TABLE laboratories ( - id SERIAL PRIMARY KEY, - name VARCHAR(255) NOT NULL UNIQUE, - description TEXT, - organization_id INT NOT NULL, - address VARCHAR(255) DEFAULT NULL, - created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, - FOREIGN KEY (organization_id) REFERENCES organizations (id) ON DELETE CASCADE -); \ No newline at end of file diff --git a/web/backend/migrations/2024-02-06-144906_create_items_table/up.sql b/web/backend/migrations/2024-02-06-144906_create_items_table/up.sql index ec84bb41..a345ae30 100644 --- a/web/backend/migrations/2024-02-06-144906_create_items_table/up.sql +++ b/web/backend/migrations/2024-02-06-144906_create_items_table/up.sql @@ -3,4 +3,5 @@ -- Items can be associated with one or more projects, and can be part of other items. -- The ownership of an item may change over time, and an item may be associated with -- one or more users. An item may have a parent item, and may be a container of other --- items. This table defines the items that are tracked and managed by the system. \ No newline at end of file +-- items. This table defines the items that are tracked and managed by the system. +-- An item can be movable or immovable. \ No newline at end of file diff --git a/web/backend/migrations/2024-02-06-145327_create_laboratory_users_table/up.sql b/web/backend/migrations/2024-02-06-145327_create_laboratory_users_table/up.sql deleted file mode 100644 index a919dd10..00000000 --- a/web/backend/migrations/2024-02-06-145327_create_laboratory_users_table/up.sql +++ /dev/null @@ -1,17 +0,0 @@ --- SQL defining the laboratory_users table. --- The laboratory_users table is a link table that links a user to a laboratory with a role. --- The user_id, laboratory_id and role columns are used to store the user, laboratory and role, and --- are used as primary keys. The created_at column is used to store the creation time of the record. --- Since only a laboratory administrator can add a user to a laboratory, the laboratory_users table --- also contains a column to specify which administrator added the user to the laboratory. -CREATE TABLE laboratory_users ( - user_id int NOT NULL, - laboratory_id int NOT NULL, - role int NOT NULL, - added_by int NOT NULL, - created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (user_id, laboratory_id, role), - FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE, - FOREIGN KEY (laboratory_id) REFERENCES laboratories (id) ON DELETE CASCADE, - FOREIGN KEY (added_by) REFERENCES users (id) ON DELETE CASCADE -); \ No newline at end of file diff --git a/web/backend/migrations/2024-02-06-145327_create_laboratory_users_table/down.sql b/web/backend/migrations/2024-02-08-085202_create_organization_locations_table/down.sql similarity index 100% rename from web/backend/migrations/2024-02-06-145327_create_laboratory_users_table/down.sql rename to web/backend/migrations/2024-02-08-085202_create_organization_locations_table/down.sql diff --git a/web/backend/migrations/2024-02-08-085202_create_organization_locations_table/up.sql b/web/backend/migrations/2024-02-08-085202_create_organization_locations_table/up.sql new file mode 100644 index 00000000..9828db77 --- /dev/null +++ b/web/backend/migrations/2024-02-08-085202_create_organization_locations_table/up.sql @@ -0,0 +1,14 @@ +-- SQL defining the organizations locations table. +-- An organization may be present in one or more locations. +-- An organization may change locations over time. +CREATE TABLE organization_locations ( + id SERIAL PRIMARY KEY, + organization_id INTEGER REFERENCES organizations(id), + location_id INTEGER REFERENCES locations(id), + previous_location_id INTEGER REFERENCES organization_locations(id), + state INTEGER NOT NULL, + created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + created_by INTEGER REFERENCES users(id), + updated_by INTEGER REFERENCES users(id) +); diff --git a/web/backend/migrations/2024-02-06-144814_create_laboratories_table/down.sql b/web/backend/migrations/2024-02-08-090153_create_container_vertical_rules_table/down.sql similarity index 64% rename from web/backend/migrations/2024-02-06-144814_create_laboratories_table/down.sql rename to web/backend/migrations/2024-02-08-090153_create_container_vertical_rules_table/down.sql index 99a91358..d9a93fe9 100644 --- a/web/backend/migrations/2024-02-06-144814_create_laboratories_table/down.sql +++ b/web/backend/migrations/2024-02-08-090153_create_container_vertical_rules_table/down.sql @@ -1,2 +1 @@ -- This file should undo anything in `up.sql` -DROP TABLE laboratories; diff --git a/web/backend/migrations/2024-02-08-090153_create_container_vertical_rules_table/up.sql b/web/backend/migrations/2024-02-08-090153_create_container_vertical_rules_table/up.sql new file mode 100644 index 00000000..0e38c6e4 --- /dev/null +++ b/web/backend/migrations/2024-02-08-090153_create_container_vertical_rules_table/up.sql @@ -0,0 +1,20 @@ +-- SQL defining the container_vertical_rules table. +-- The container rules define whether an item type can contain another item type. +-- For instance a rack can contain tubes, but a tube cannot contain a rack. +-- We define such rules in an allow-list fashion, meaning that if a rule is not defined, +-- then the item type cannot contain another item type. The rules are defined by an admin +-- user, and are used to enforce the containment rules when creating or updating items. +-- Some containers may only contain items that are within a certain temperature, humidity, +-- or pressure range. These constraints are also defined in the container rules. +CREATE TABLE container_vertical_rules ( + id SERIAL PRIMARY KEY, + container_item_type_id INTEGER REFERENCES item_types(id), + contained_item_type_id INTEGER REFERENCES item_types(id), + temperature INTERVAL DEFAULT NULL, + humidity INTERVAL DEFAULT NULL, + pressure INTERVAL DEFAULT NULL, + created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + created_by INTEGER REFERENCES users(id), + updated_by INTEGER REFERENCES users(id) +); \ No newline at end of file diff --git a/web/backend/migrations/2024-02-08-090409_create_item_types_table/down.sql b/web/backend/migrations/2024-02-08-090409_create_item_types_table/down.sql new file mode 100644 index 00000000..d9a93fe9 --- /dev/null +++ b/web/backend/migrations/2024-02-08-090409_create_item_types_table/down.sql @@ -0,0 +1 @@ +-- This file should undo anything in `up.sql` diff --git a/web/backend/migrations/2024-02-08-090409_create_item_types_table/up.sql b/web/backend/migrations/2024-02-08-090409_create_item_types_table/up.sql new file mode 100644 index 00000000..a1419f0b --- /dev/null +++ b/web/backend/migrations/2024-02-08-090409_create_item_types_table/up.sql @@ -0,0 +1,15 @@ +-- SQL defining the item_types table. +-- An item type is a type of item that can be tracked and managed, may have a cost, +-- 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). +CREATE TABLE item_types ( + id SERIAL PRIMARY KEY, + name VARCHAR(255) NOT NULL UNIQUE, + description TEXT, + 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 +); \ No newline at end of file diff --git a/web/backend/migrations/2024-02-08-091232_create_container_horizontal_rules_table/down.sql b/web/backend/migrations/2024-02-08-091232_create_container_horizontal_rules_table/down.sql new file mode 100644 index 00000000..d9a93fe9 --- /dev/null +++ b/web/backend/migrations/2024-02-08-091232_create_container_horizontal_rules_table/down.sql @@ -0,0 +1 @@ +-- This file should undo anything in `up.sql` diff --git a/web/backend/migrations/2024-02-08-091232_create_container_horizontal_rules_table/up.sql b/web/backend/migrations/2024-02-08-091232_create_container_horizontal_rules_table/up.sql new file mode 100644 index 00000000..f33051da --- /dev/null +++ b/web/backend/migrations/2024-02-08-091232_create_container_horizontal_rules_table/up.sql @@ -0,0 +1,21 @@ +-- SQL defining the container_horizontal_rules table. +-- The container horizontal rules define whether an item type can be placed next to another item type. +-- For instance a acid product cannot be placed next to a base product. Generally speaking, most items +-- can be placed next to each other, but some items cannot be placed next to each other. These rules +-- are defined in the form of a deny-list, meaning that if a rule is not defined, then the item type +-- can be placed next to any other item type. The rules are defined by an admin user, and are used to +-- enforce the placement rules when creating or updating items. Some items may only be placed next to +-- items that are within a certain temperature, humidity, or pressure range. These constraints are also +-- defined in the container rules. +CREATE TABLE container_horizontal_rules ( + id SERIAL PRIMARY KEY, + item_type_id INTEGER REFERENCES item_types(id), + other_item_type_id INTEGER REFERENCES item_types(id), + temperature INTERVAL DEFAULT NULL, + humidity INTERVAL DEFAULT NULL, + pressure INTERVAL DEFAULT NULL, + created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + created_by INTEGER REFERENCES users(id), + updated_by INTEGER REFERENCES users(id) +); \ No newline at end of file diff --git a/web/backend/migrations/2024-02-08-100852_create_manifactured_item_types_table/down.sql b/web/backend/migrations/2024-02-08-100852_create_manifactured_item_types_table/down.sql new file mode 100644 index 00000000..d9a93fe9 --- /dev/null +++ b/web/backend/migrations/2024-02-08-100852_create_manifactured_item_types_table/down.sql @@ -0,0 +1 @@ +-- This file should undo anything in `up.sql` diff --git a/web/backend/migrations/2024-02-08-100852_create_manifactured_item_types_table/up.sql b/web/backend/migrations/2024-02-08-100852_create_manifactured_item_types_table/up.sql new file mode 100644 index 00000000..2eb9603b --- /dev/null +++ b/web/backend/migrations/2024-02-08-100852_create_manifactured_item_types_table/up.sql @@ -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 +); \ No newline at end of file diff --git a/web/backend/migrations/2024-02-08-101004_create_expirable_item_types_table/down.sql b/web/backend/migrations/2024-02-08-101004_create_expirable_item_types_table/down.sql new file mode 100644 index 00000000..b7182790 --- /dev/null +++ b/web/backend/migrations/2024-02-08-101004_create_expirable_item_types_table/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +DROP TABLE expirable_item_types; diff --git a/web/backend/migrations/2024-02-08-101004_create_expirable_item_types_table/up.sql b/web/backend/migrations/2024-02-08-101004_create_expirable_item_types_table/up.sql new file mode 100644 index 00000000..e2d0c58d --- /dev/null +++ b/web/backend/migrations/2024-02-08-101004_create_expirable_item_types_table/up.sql @@ -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 +); \ No newline at end of file