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 8bed5e6d..06923d5b 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 @@ -6,4 +6,22 @@ -- items. This table defines the items that are tracked and managed by the system. -- An item can be movable or immovable. -- An example of an Item may be a measurement device, a tube potentially containing a sample, --- or a sample itself. \ No newline at end of file +-- or a sample itself. +CREATE TABLE items ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + name TEXT NOT NULL, + description TEXT, + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT now(), + created_by UUID NOT NULL, + updated_by UUID NOT NULL, + project_id UUID NOT NULL, + parent_id UUID, + location_id UUID, + FOREIGN KEY (created_by) REFERENCES users(id), + FOREIGN KEY (updated_by) REFERENCES users(id), + FOREIGN KEY (project_id) REFERENCES projects(id), + FOREIGN KEY (parent_id) REFERENCES items(id), + FOREIGN KEY (item_type_id) REFERENCES item_types(id), + FOREIGN KEY (location_id) REFERENCES locations(id) +); \ No newline at end of file diff --git a/web/backend/migrations/2024-02-09-143242_create_item_weights_table/down.sql b/web/backend/migrations/2024-02-09-143242_create_item_weights_table/down.sql new file mode 100644 index 00000000..d9a93fe9 --- /dev/null +++ b/web/backend/migrations/2024-02-09-143242_create_item_weights_table/down.sql @@ -0,0 +1 @@ +-- This file should undo anything in `up.sql` diff --git a/web/backend/migrations/2024-02-09-143242_create_item_weights_table/up.sql b/web/backend/migrations/2024-02-09-143242_create_item_weights_table/up.sql new file mode 100644 index 00000000..7bac0bef --- /dev/null +++ b/web/backend/migrations/2024-02-09-143242_create_item_weights_table/up.sql @@ -0,0 +1,18 @@ +-- SQL defining the item_weights table. +-- Each item, being a physical object, has a weight. This table defines the weights of items. +-- The weight of an item may change over time, and be measured using different scales and by +-- different people. +CREATE TABLE item_weights ( + id SERIAL PRIMARY KEY, + item_id INTEGER REFERENCES items(id), + weight DECIMAL(10, 2) NOT NULL, + weight_unit_id INTEGER REFERENCES weight_units(id), + sensor_id INTEGER REFERENCES items(id), + measured_at TIMESTAMPTZ NOT NULL DEFAULT now(), + measured_by INTEGER REFERENCES users(id), + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT now(), + created_by INTEGER NOT NULL REFERENCES users(id), + updated_by INTEGER NOT NULL REFERENCES users(id), + FOREIGN KEY (item_id, weight_unit_id) REFERENCES items(item_id, weight_unit_id), +); \ No newline at end of file diff --git a/web/backend/migrations/2024-02-09-144314_create_item_quantities_table/down.sql b/web/backend/migrations/2024-02-09-144314_create_item_quantities_table/down.sql new file mode 100644 index 00000000..d9a93fe9 --- /dev/null +++ b/web/backend/migrations/2024-02-09-144314_create_item_quantities_table/down.sql @@ -0,0 +1 @@ +-- This file should undo anything in `up.sql` diff --git a/web/backend/migrations/2024-02-09-144314_create_item_quantities_table/up.sql b/web/backend/migrations/2024-02-09-144314_create_item_quantities_table/up.sql new file mode 100644 index 00000000..946d8ce9 --- /dev/null +++ b/web/backend/migrations/2024-02-09-144314_create_item_quantities_table/up.sql @@ -0,0 +1,21 @@ +-- SQL defining the item_quantities table. +-- Some items may be counted discretely, as opposed to a weight in grams. +-- This table defines the discrete quantities of items that we have in stock. +-- The quantity of an item may change over time, so multiple quantity entries +-- may be inserted for the same item. +-- While these quantities are discrete, in order to facilitate the semantics of +-- the system, we will still allow for the user to specify the counter unit for +-- the item. For example, a counter unit may be a box, a tube, or a vial. +CREATE TABLE item_quantities ( + id SERIAL PRIMARY KEY, + item_id INTEGER REFERENCES items(id), + quantity INTEGER NOT NULL, + unit_id INTEGER REFERENCES weight_units(id), + measured_at TIMESTAMPTZ NOT NULL DEFAULT now(), + measured_by INTEGER REFERENCES users(id), + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT now(), + created_by INTEGER NOT NULL REFERENCES users(id), + updated_by INTEGER NOT NULL REFERENCES users(id), + FOREIGN KEY (item_id, unit_id) REFERENCES item_units(item_id, unit_id), +); \ No newline at end of file