Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions database/sql/fixture/waste_fixture.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- waste
-- waste type
INSERT INTO container_type (last_update_by, container_type_name, container_type_description) VALUES
('Thato', 'Glass', 'Used for collecting glass waste like bottles and jars'),
('Thato', 'Plastic', 'Used for collecting waste like plastic bottles, containers and packaging'),
('Thato', 'Cans', 'Used for collecting waste like aluminium and tin cans'),
('Thato', 'Paper', 'Used for collecting waste like paper, cardboard and newspaper'),
('Thato', 'General', 'Used for unsorted or mixed domestic waste');

-- containers condition
INSERT INTO container_condition (last_update_by, condition_name, condition_description) VALUES
('Thato', 'Good', 'No damage, fully functional'),
('Thato', 'Damaged', 'Cracked or broken lid, partially usable'),
('Thato', 'Fair', 'Minor dents or wear but functional'),
('Thato', 'Leaking', 'Liquid seeping from base or sides');

-- waste fill level
INSERT INTO waste_level (last_update_by, level_name, level_description) VALUES
('Thato', 'Empty', 'No waste inside'),
('Thato', 'Half', 'Approximately 50% full'),
('Thato', 'Full', 'Completely full, should be emptied'),
('Thato', 'Overflowing', 'Exceeds capacity, waste spilling out');
3 changes: 2 additions & 1 deletion scripts/load_schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ $PSQL gis -f sql/10-gates.sql
$PSQL gis -f sql/11-poles.sql
$PSQL gis -f sql/12-culinary.sql
$PSQL gis -f sql/13-roads.sql
$PSQL gis -f sql/fixtures.sql
$PSQL gis -f sql/14-waste.sql
$PSQL gis -f sql/fixtures.sql
104 changes: 104 additions & 0 deletions sql/14-waste.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
----------------------------------------WASTE--------------------------------------------

-- CONTAINER TYPE
CREATE TABLE IF NOT EXISTS container_type (
id SERIAL NOT NULL PRIMARY KEY,
uuid UUID UNIQUE NOT NULL DEFAULT gen_random_uuid(),
last_update TIMESTAMP DEFAULT now() NOT NULL,
last_update_by TEXT NOT NULL,
type_name VARCHAR UNIQUE NOT NULL,
description TEXT
);
COMMENT ON TABLE container_type IS 'Lookup table for types of waste containers (e.g. "Glass", "Plastic").';
COMMENT ON COLUMN container_type.id IS 'The unique container type ID. This is the Primary Key.';
COMMENT ON COLUMN container_type.uuid IS 'Global Unique Identifier.';
COMMENT ON COLUMN container_type.last_update IS 'The date the last update was made (yyyy-mm-dd hh:mm:ss).';
COMMENT ON COLUMN container_type.last_update_by IS 'The name of the user responsible for the latest update.';
COMMENT ON COLUMN container_type.type_name IS 'The descriptive name for the container type. This is unique.';
COMMENT ON COLUMN container_type.description IS 'Additional information about the container type.';


-- CONTAINER CONDITION
CREATE TABLE IF NOT EXISTS container_condition (
id SERIAL NOT NULL PRIMARY KEY,
uuid UUID UNIQUE NOT NULL DEFAULT gen_random_uuid(),
last_update TIMESTAMP DEFAULT now() NOT NULL,
last_update_by TEXT NOT NULL,
condition_name VARCHAR UNIQUE NOT NULL,
description TEXT
);
COMMENT ON TABLE container_condition IS 'Physical condition status of a container (e.g. "Good", "Damaged").';
COMMENT ON COLUMN container_condition.id IS 'The unique container condition ID. This is the Primary Key.';
COMMENT ON COLUMN container_condition.uuid IS 'Global Unique Identifier.';
COMMENT ON COLUMN container_condition.last_update IS 'The date the last update was made (yyyy-mm-dd hh:mm:ss).';
COMMENT ON COLUMN container_condition.last_update_by IS 'The name of the user responsible for the latest update.';
COMMENT ON COLUMN container_condition.condition_name IS 'The name of the container condition. This is unique.';
COMMENT ON COLUMN container_condition.description IS 'Additional information about the container condition.';


-- WASTE LEVEL
CREATE TABLE IF NOT EXISTS waste_level (
id SERIAL NOT NULL PRIMARY KEY,
uuid UUID UNIQUE NOT NULL DEFAULT gen_random_uuid(),
last_update TIMESTAMP DEFAULT now() NOT NULL,
last_update_by TEXT NOT NULL,
level_name VARCHAR UNIQUE NOT NULL,
description TEXT
);
COMMENT ON TABLE waste_level IS 'Fill level of the container (e.g. "Empty", "Full").';
COMMENT ON COLUMN waste_level.id IS 'The unique waste level ID. This is the Primary Key.';
COMMENT ON COLUMN waste_level.uuid IS 'Global Unique Identifier.';
COMMENT ON COLUMN waste_level.last_update IS 'The date the last update was made (yyyy-mm-dd hh:mm:ss).';
COMMENT ON COLUMN waste_level.last_update_by IS 'The name of the user responsible for the latest update.';
COMMENT ON COLUMN waste_level.level_name IS 'The name of the waste level. This is unique.';
COMMENT ON COLUMN waste_level.description IS 'Additional information about the waste level.';


-- WASTE CONTAINER
CREATE TABLE IF NOT EXISTS waste_container (
id SERIAL NOT NULL PRIMARY KEY,
uuid UUID UNIQUE NOT NULL DEFAULT gen_random_uuid(),
last_update TIMESTAMP DEFAULT now() NOT NULL,
last_update_by TEXT NOT NULL,
covered BOOLEAN,
capacity_liters INT CHECK (capacity_liters > 0),
geom GEOMETRY (POINT, 4326),
type_uuid UUID NOT NULL REFERENCES container_type (uuid)
);
COMMENT ON TABLE waste_container IS 'Waste containers used in the field, linked to container type and location.';
COMMENT ON COLUMN waste_container.id IS 'The unique waste container ID. This is the Primary Key.';
COMMENT ON COLUMN waste_container.uuid IS 'Global Unique Identifier.';
COMMENT ON COLUMN waste_container.last_update IS 'The date the last update was made (yyyy-mm-dd hh:mm:ss).';
COMMENT ON COLUMN waste_container.last_update_by IS 'The name of the user responsible for the latest update.';
COMMENT ON COLUMN waste_container.covered IS 'True if the container has a cover.';
COMMENT ON COLUMN waste_container.capacity_liters IS 'Capacity of the container in liters.';
COMMENT ON COLUMN waste_container.geom IS 'Location of the waste container. EPSG: 4326 (WGS 84).';
COMMENT ON COLUMN waste_container.type_uuid IS 'Foreign key referencing container type.';

-- WASTE LOG
CREATE TABLE IF NOT EXISTS waste_log (
id SERIAL NOT NULL PRIMARY KEY,
uuid UUID UNIQUE NOT NULL DEFAULT gen_random_uuid(),
last_update TIMESTAMP DEFAULT now() NOT NULL,
last_update_by TEXT NOT NULL,
log_description TEXT,
observation_date DATE,
observation_time TIME,
container_uuid UUID NOT NULL REFERENCES waste_container (uuid),
condition_uuid UUID NOT NULL REFERENCES container_condition (uuid),
level_uuid UUID NOT NULL REFERENCES waste_level (uuid)

);
COMMENT ON TABLE waste_log IS 'Observations made about waste containers including condition and fill level.';
COMMENT ON COLUMN waste_log.id IS 'The unique waste log ID. This is the Primary Key.';
COMMENT ON COLUMN waste_log.uuid IS 'Global Unique Identifier.';
COMMENT ON COLUMN waste_log.last_update IS 'The date the last update was made (yyyy-mm-dd hh:mm:ss).';
COMMENT ON COLUMN waste_log.last_update_by IS 'The name of the user responsible for the latest update.';
COMMENT ON COLUMN waste_log.log_description IS 'Description of the observation or issue.';
COMMENT ON COLUMN waste_log.observation_date IS 'Date of the observation.';
COMMENT ON COLUMN waste_log.observation_time IS 'Time of the observation.';
COMMENT ON COLUMN waste_log.container_uuid IS 'Foreign key referencing the waste container.';
COMMENT ON COLUMN waste_log.condition_uuid IS 'Foreign key referencing the container condition.';
COMMENT ON COLUMN waste_log.level_uuid IS 'Foreign key referencing the waste level.';
-- trigger action
-- force CI trigger