-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more tables for weights and discrete quantities
- Loading branch information
1 parent
e92118a
commit e06f94c
Showing
5 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
web/backend/migrations/2024-02-09-143242_create_item_weights_table/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-- This file should undo anything in `up.sql` |
18 changes: 18 additions & 0 deletions
18
web/backend/migrations/2024-02-09-143242_create_item_weights_table/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
); |
1 change: 1 addition & 0 deletions
1
web/backend/migrations/2024-02-09-144314_create_item_quantities_table/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-- This file should undo anything in `up.sql` |
21 changes: 21 additions & 0 deletions
21
web/backend/migrations/2024-02-09-144314_create_item_quantities_table/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
); |