Skip to content

Commit

Permalink
Worked more on tables
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaCappelletti94 committed Feb 8, 2024
1 parent ec8f5b5 commit f98fbc3
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 34 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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.
-- items. This table defines the items that are tracked and managed by the system.
-- An item can be movable or immovable.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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)
);
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
-- This file should undo anything in `up.sql`
DROP TABLE laboratories;
Original file line number Diff line number Diff line change
@@ -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)
);
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,27 @@
-- 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). 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.
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,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
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 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)
);

0 comments on commit f98fbc3

Please sign in to comment.