2024-10-16 12:01:16 +02:00
|
|
|
-- Cleanup existing database content.
|
|
|
|
DROP SCHEMA public CASCADE;
|
|
|
|
CREATE SCHEMA public;
|
|
|
|
|
2024-11-22 15:40:10 +01:00
|
|
|
-- Create models table.
|
2024-10-16 12:01:16 +02:00
|
|
|
CREATE TABLE models (
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
name VARCHAR NOT NULL,
|
|
|
|
amount NUMERIC(12, 2) NOT NULL
|
|
|
|
);
|
|
|
|
|
2024-11-22 15:40:10 +01:00
|
|
|
-- Create submodels table.
|
|
|
|
CREATE TABLE submodels (
|
|
|
|
uuid UUID PRIMARY KEY,
|
|
|
|
label VARCHAR NOT NULL,
|
|
|
|
parent_id INT NULL,
|
|
|
|
FOREIGN KEY (parent_id) REFERENCES models ON DELETE RESTRICT ON UPDATE CASCADE
|
|
|
|
);
|
|
|
|
CREATE INDEX submodels_parent_id_index ON submodels(parent_id);
|
|
|
|
|
2024-10-16 12:01:16 +02:00
|
|
|
-- Insert default data.
|
|
|
|
INSERT INTO models(name, amount) VALUES ('test', 50);
|
2024-10-22 15:44:41 +02:00
|
|
|
INSERT INTO models(name, amount) VALUES ('updatable', 33.12);
|
2024-11-22 15:40:10 +01:00
|
|
|
INSERT INTO submodels(uuid, label, parent_id) VALUES ('f6868a5b-2efc-455f-b76e-872df514404f', 'test', 1);
|
|
|
|
INSERT INTO submodels(uuid, label, parent_id) VALUES ('013ef171-9781-40e9-b843-f6bc11890070', 'another', 1);
|
2024-10-16 12:01:16 +02:00
|
|
|
|
2024-11-22 15:40:10 +01:00
|
|
|
-- Create composite models table.
|
2024-10-16 12:01:16 +02:00
|
|
|
CREATE TABLE composite_models (
|
|
|
|
firstcol SERIAL NOT NULL,
|
|
|
|
secondcol VARCHAR NOT NULL,
|
|
|
|
label VARCHAR NULL,
|
|
|
|
PRIMARY KEY (firstcol, secondcol)
|
|
|
|
);
|