Skip to content

Commit

Permalink
Added more tables for weights and discrete quantities
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaCappelletti94 committed Feb 9, 2024
1 parent e92118a commit e06f94c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
-- 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)
);
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,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),
);
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,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),
);

0 comments on commit e06f94c

Please sign in to comment.