From 19b690b66589033a8a155cc045e92597aa42b904 Mon Sep 17 00:00:00 2001 From: wqy Date: Sat, 3 Sep 2022 14:04:44 +0800 Subject: [PATCH] Start database api work --- script/script/api/create/1.title.sql | 22 ++++++++++ script/script/table/create/0.base.sql | 25 +++++++++++ script/script/table/create/1.title.sql | 8 ++++ script/script/table/create/10.status.sql | 29 +++++++++++++ script/script/table/create/11.patterns.sql | 7 ++++ script/script/table/create/12.curves.sql | 8 ++++ script/script/table/create/13.controls.sql | 30 +++++++++++++ script/script/table/create/14.rules.sql | 6 +++ script/script/table/create/15.energy.sql | 24 +++++++++++ script/script/table/create/16.emitters.sql | 7 ++++ script/script/table/create/17.quality.sql | 7 ++++ script/script/table/create/18.sources.sql | 11 +++++ script/script/table/create/19.reactions.sql | 42 +++++++++++++++++++ script/script/table/create/2.junctions.sql | 9 ++++ script/script/table/create/20.mixing.sql | 10 +++++ script/script/table/create/21.times.sql | 9 ++++ script/script/table/create/22.report.sql | 9 ++++ script/script/table/create/23.options.sql | 9 ++++ script/script/table/create/24.coordinates.sql | 10 +++++ script/script/table/create/25.vertices.sql | 8 ++++ script/script/table/create/26.labels.sql | 9 ++++ script/script/table/create/27.backdrop.sql | 6 +++ script/script/table/create/28.end.sql | 1 + script/script/table/create/3.reservoirs.sql | 8 ++++ script/script/table/create/4.tanks.sql | 16 +++++++ script/script/table/create/5.pipes.sql | 15 +++++++ script/script/table/create/6.pumps.sql | 32 ++++++++++++++ script/script/table/create/7.valves.sql | 14 +++++++ script/script/table/create/8.tags.sql | 13 ++++++ script/script/table/create/9.demands.sql | 9 ++++ script/script/table/create/namespace.sql | 1 + script/script/table/create/operation.sql | 29 +++++++++++++ script/script/table/drop/0.base.sql | 11 +++++ script/script/table/drop/1.title.sql | 3 ++ script/script/table/drop/10.status.sql | 13 ++++++ script/script/table/drop/11.patterns.sql | 3 ++ script/script/table/drop/12.curves.sql | 3 ++ script/script/table/drop/13.controls.sql | 9 ++++ script/script/table/drop/14.rules.sql | 3 ++ script/script/table/drop/15.energy.sql | 9 ++++ script/script/table/drop/16.emitters.sql | 3 ++ script/script/table/drop/17.quality.sql | 3 ++ script/script/table/drop/18.sources.sql | 5 +++ script/script/table/drop/19.reactions.sql | 19 +++++++++ script/script/table/drop/2.junctions.sql | 3 ++ script/script/table/drop/20.mixing.sql | 5 +++ script/script/table/drop/21.times.sql | 3 ++ script/script/table/drop/22.report.sql | 3 ++ script/script/table/drop/23.options.sql | 3 ++ script/script/table/drop/24.coordinates.sql | 7 ++++ script/script/table/drop/25.vertices.sql | 3 ++ script/script/table/drop/26.labels.sql | 3 ++ script/script/table/drop/27.backdrop.sql | 3 ++ script/script/table/drop/28.end.sql | 1 + script/script/table/drop/3.reservoirs.sql | 3 ++ script/script/table/drop/4.tanks.sql | 5 +++ script/script/table/drop/5.pipes.sql | 5 +++ script/script/table/drop/6.pumps.sql | 11 +++++ script/script/table/drop/7.valves.sql | 5 +++ script/script/table/drop/8.tags.sql | 5 +++ script/script/table/drop/9.demands.sql | 3 ++ script/script/table/drop/namespace.sql | 1 + script/script/table/drop/operation.sql | 7 ++++ 63 files changed, 606 insertions(+) create mode 100644 script/script/api/create/1.title.sql create mode 100644 script/script/table/create/0.base.sql create mode 100644 script/script/table/create/1.title.sql create mode 100644 script/script/table/create/10.status.sql create mode 100644 script/script/table/create/11.patterns.sql create mode 100644 script/script/table/create/12.curves.sql create mode 100644 script/script/table/create/13.controls.sql create mode 100644 script/script/table/create/14.rules.sql create mode 100644 script/script/table/create/15.energy.sql create mode 100644 script/script/table/create/16.emitters.sql create mode 100644 script/script/table/create/17.quality.sql create mode 100644 script/script/table/create/18.sources.sql create mode 100644 script/script/table/create/19.reactions.sql create mode 100644 script/script/table/create/2.junctions.sql create mode 100644 script/script/table/create/20.mixing.sql create mode 100644 script/script/table/create/21.times.sql create mode 100644 script/script/table/create/22.report.sql create mode 100644 script/script/table/create/23.options.sql create mode 100644 script/script/table/create/24.coordinates.sql create mode 100644 script/script/table/create/25.vertices.sql create mode 100644 script/script/table/create/26.labels.sql create mode 100644 script/script/table/create/27.backdrop.sql create mode 100644 script/script/table/create/28.end.sql create mode 100644 script/script/table/create/3.reservoirs.sql create mode 100644 script/script/table/create/4.tanks.sql create mode 100644 script/script/table/create/5.pipes.sql create mode 100644 script/script/table/create/6.pumps.sql create mode 100644 script/script/table/create/7.valves.sql create mode 100644 script/script/table/create/8.tags.sql create mode 100644 script/script/table/create/9.demands.sql create mode 100644 script/script/table/create/namespace.sql create mode 100644 script/script/table/create/operation.sql create mode 100644 script/script/table/drop/0.base.sql create mode 100644 script/script/table/drop/1.title.sql create mode 100644 script/script/table/drop/10.status.sql create mode 100644 script/script/table/drop/11.patterns.sql create mode 100644 script/script/table/drop/12.curves.sql create mode 100644 script/script/table/drop/13.controls.sql create mode 100644 script/script/table/drop/14.rules.sql create mode 100644 script/script/table/drop/15.energy.sql create mode 100644 script/script/table/drop/16.emitters.sql create mode 100644 script/script/table/drop/17.quality.sql create mode 100644 script/script/table/drop/18.sources.sql create mode 100644 script/script/table/drop/19.reactions.sql create mode 100644 script/script/table/drop/2.junctions.sql create mode 100644 script/script/table/drop/20.mixing.sql create mode 100644 script/script/table/drop/21.times.sql create mode 100644 script/script/table/drop/22.report.sql create mode 100644 script/script/table/drop/23.options.sql create mode 100644 script/script/table/drop/24.coordinates.sql create mode 100644 script/script/table/drop/25.vertices.sql create mode 100644 script/script/table/drop/26.labels.sql create mode 100644 script/script/table/drop/27.backdrop.sql create mode 100644 script/script/table/drop/28.end.sql create mode 100644 script/script/table/drop/3.reservoirs.sql create mode 100644 script/script/table/drop/4.tanks.sql create mode 100644 script/script/table/drop/5.pipes.sql create mode 100644 script/script/table/drop/6.pumps.sql create mode 100644 script/script/table/drop/7.valves.sql create mode 100644 script/script/table/drop/8.tags.sql create mode 100644 script/script/table/drop/9.demands.sql create mode 100644 script/script/table/drop/namespace.sql create mode 100644 script/script/table/drop/operation.sql diff --git a/script/script/api/create/1.title.sql b/script/script/api/create/1.title.sql new file mode 100644 index 0000000..31340b8 --- /dev/null +++ b/script/script/api/create/1.title.sql @@ -0,0 +1,22 @@ +-- get_title() +create function get_title() returns text as +$$ + select value from title; +$$ language sql; + +-- update_title() +create function update_title(new_title text) returns void as +$$ +declare + old_title text; + redo text; + undo text; +begin + select get_title() into old_title; + update title set value = new_title where value = old_title; + + redo := concat('update title set value = ''', new_title, ''' where value = ''', old_title, ''''); + undo := concat('update title set value = ''', old_title, ''' where value = ''', new_title, ''''); + insert into operation values (default, redo, undo); +end; +$$ language plpgsql; diff --git a/script/script/table/create/0.base.sql b/script/script/table/create/0.base.sql new file mode 100644 index 0000000..5ae4026 --- /dev/null +++ b/script/script/table/create/0.base.sql @@ -0,0 +1,25 @@ +create type tj.node_type as enum ('junction', 'reservoir', 'tank'); + +create type tj.link_type as enum ('pipe', 'pump', 'valve'); + +create table tj.node +( + id varchar(32) primary key +, type tj.node_type not null +); + +create table tj.link +( + id varchar(32) primary key +, type tj.link_type not null +); + +create table tj.curve +( + id varchar(32) primary key +); + +create table tj.pattern +( + id varchar(32) primary key +); diff --git a/script/script/table/create/1.title.sql b/script/script/table/create/1.title.sql new file mode 100644 index 0000000..c00e981 --- /dev/null +++ b/script/script/table/create/1.title.sql @@ -0,0 +1,8 @@ +-- [TITLE] + +CREATE TABLE TITLE +( + Value TEXT +); + +INSERT INTO TITLE (Value) VALUES (''); diff --git a/script/script/table/create/10.status.sql b/script/script/table/create/10.status.sql new file mode 100644 index 0000000..34da1f7 --- /dev/null +++ b/script/script/table/create/10.status.sql @@ -0,0 +1,29 @@ +-- [STATUS] + +CREATE TYPE STATUS_PIPE_PUMP_STATUS AS ENUM ('OPEN', 'CLOSED'); + +CREATE TABLE STATUS_PIPE +( + ID VARCHAR(32) PRIMARY KEY REFERENCES PIPES(ID) +, Status STATUS_PIPE_PUMP_STATUS NOT NULL +); + +CREATE TABLE STATUS_PUMP +( + ID VARCHAR(32) PRIMARY KEY REFERENCES PUMPS(ID) +, Status STATUS_PIPE_PUMP_STATUS NOT NULL +); + +CREATE TYPE STATUS_VALVE_STATUS AS ENUM ('OPEN', 'CLOSED', 'ACTIVE'); + +CREATE TABLE STATUS_VALVE +( + ID VARCHAR(32) PRIMARY KEY REFERENCES VALVES(ID) +, Status STATUS_VALVE_STATUS NOT NULL +); + +CREATE TABLE STATUS_LINK +( + ID VARCHAR(32) PRIMARY KEY REFERENCES _LINK(ID) +, Setting NUMERIC NOT NULL +); diff --git a/script/script/table/create/11.patterns.sql b/script/script/table/create/11.patterns.sql new file mode 100644 index 0000000..dfb23b0 --- /dev/null +++ b/script/script/table/create/11.patterns.sql @@ -0,0 +1,7 @@ +-- [PATTERNS] + +CREATE TABLE PATTERNS +( + ID VARCHAR(32) REFERENCES _PATTERN(ID) NOT NULL +, Multipliers NUMERIC NOT NULL +); diff --git a/script/script/table/create/12.curves.sql b/script/script/table/create/12.curves.sql new file mode 100644 index 0000000..ac2460e --- /dev/null +++ b/script/script/table/create/12.curves.sql @@ -0,0 +1,8 @@ +-- [CURVES] + +CREATE TABLE CURVES +( + ID VARCHAR(32) REFERENCES _CURVE(ID) NOT NULL +, X NUMERIC NOT NULL +, Y NUMERIC NOT NULL +); diff --git a/script/script/table/create/13.controls.sql b/script/script/table/create/13.controls.sql new file mode 100644 index 0000000..aa107eb --- /dev/null +++ b/script/script/table/create/13.controls.sql @@ -0,0 +1,30 @@ +-- [CONTROLS] + +CREATE TYPE CONTROLS_1_PREP AS ENUM ('ABOVE', 'BELOW'); + +-- LINK linkID status IF NODE nodeID ABOVE / BELOW value +CREATE TABLE CONTROLS_1 +( + LinkID VARCHAR(32) PRIMARY KEY REFERENCES _LINK(ID) +, Status TEXT NOT NULL -- OPEN / CLOSED, a pump speed setting, or a control valve setting +, NodeID VARCHAR(32) REFERENCES _NODE(ID) NOT NULL +, Prep CONTROLS_1_PREP NOT NULL +, Value NUMERIC NOT NULL +); + +-- LINK linkID status AT TIME time +CREATE TABLE CONTROLS_2 +( + LinkID VARCHAR(32) PRIMARY KEY REFERENCES _LINK(ID) +, Status TEXT NOT NULL -- OPEN / CLOSED, a pump speed setting, or a control valve setting +, Time INTERVAL HOUR +); + +-- LINK linkID status AT CLOCKTIME clocktime AM / PM +CREATE TABLE CONTROLS_3 +( + LinkID VARCHAR(32) PRIMARY KEY REFERENCES _LINK(ID) +, Status TEXT NOT NULL -- OPEN / CLOSED, a pump speed setting, or a control valve setting +, ClockTimeHour INTERVAL HOUR -- get AM/PM from it +, ClockTimeMin INTERVAL MINUTE +); diff --git a/script/script/table/create/14.rules.sql b/script/script/table/create/14.rules.sql new file mode 100644 index 0000000..7d288ca --- /dev/null +++ b/script/script/table/create/14.rules.sql @@ -0,0 +1,6 @@ +-- [RULES] + +CREATE TABLE RULES +( + Content TEXT PRIMARY KEY +); diff --git a/script/script/table/create/15.energy.sql b/script/script/table/create/15.energy.sql new file mode 100644 index 0000000..a73a3db --- /dev/null +++ b/script/script/table/create/15.energy.sql @@ -0,0 +1,24 @@ +-- [ENERGY] + +CREATE TYPE ENERGY_PARAM AS ENUM ('PRICE', 'PATTERN', 'EFFIC'); + +-- GLOBAL PRICE / PATTERN / EFFIC value +CREATE TABLE ENERGY_GLOBAL +( + Param ENERGY_PARAM NOT NULL +, Value NUMERIC NOT NULL +); + +-- PUMP pumpID PRICE / PATTERN / EFFIC value +CREATE TABLE ENERGY_PUMP +( + ID VARCHAR(32) REFERENCES PUMPS(ID) NOT NULL +, Param ENERGY_PARAM NOT NULL +, Value NUMERIC NOT NULL +); + +-- DEMAND CHARGE value +CREATE TABLE ENERGY_DEMAND_CHARGE +( + Value NUMERIC NOT NULL +); diff --git a/script/script/table/create/16.emitters.sql b/script/script/table/create/16.emitters.sql new file mode 100644 index 0000000..b1fe8b4 --- /dev/null +++ b/script/script/table/create/16.emitters.sql @@ -0,0 +1,7 @@ +-- [EMITTERS] + +CREATE TABLE EMITTERS +( + Junction VARCHAR(32) PRIMARY KEY REFERENCES JUNCTIONS(ID) +, Coefficient NUMERIC NOT NULL +); diff --git a/script/script/table/create/17.quality.sql b/script/script/table/create/17.quality.sql new file mode 100644 index 0000000..939e309 --- /dev/null +++ b/script/script/table/create/17.quality.sql @@ -0,0 +1,7 @@ +-- [QUALITY] + +CREATE TABLE QUALITY +( + Node VARCHAR(32) PRIMARY KEY REFERENCES _NODE(ID) +, InitialQual NUMERIC NOT NULL +); diff --git a/script/script/table/create/18.sources.sql b/script/script/table/create/18.sources.sql new file mode 100644 index 0000000..1c2ec64 --- /dev/null +++ b/script/script/table/create/18.sources.sql @@ -0,0 +1,11 @@ +-- [SOURCES] + +CREATE TYPE SOURCES_TYPE AS ENUM ('CONCEN', 'MASS', 'FLOWPACED', 'SETPOINT'); + +CREATE TABLE SOURCES +( + Node VARCHAR(32) PRIMARY KEY REFERENCES _NODE(ID) +, Type SOURCES_TYPE NOT NULL +, Strength NUMERIC NOT NULL +, TimePattern VARCHAR(32) REFERENCES _PATTERN(ID) +); diff --git a/script/script/table/create/19.reactions.sql b/script/script/table/create/19.reactions.sql new file mode 100644 index 0000000..0d8d13b --- /dev/null +++ b/script/script/table/create/19.reactions.sql @@ -0,0 +1,42 @@ +-- [REACTIONS] + +CREATE TYPE REACTIONS_ORDER_PARAM AS ENUM ('BULK', 'WALL', 'TANK'); + +CREATE TABLE REACTIONS_ORDER +( + Key REACTIONS_ORDER_PARAM NOT NULL +, Value NUMERIC NOT NULL +); + +CREATE TYPE REACTIONS_GLOBAL_PARAM AS ENUM ('BULK', 'WALL'); + +CREATE TABLE REACTIONS_GLOBAL +( + Key REACTIONS_GLOBAL_PARAM NOT NULL +, Value NUMERIC NOT NULL +); + +CREATE TYPE REACTIONS_PIPE_PARAM AS ENUM ('BULK', 'WALL'); + +CREATE TABLE REACTIONS_PIPE +( + Key REACTIONS_PIPE_PARAM NOT NULL +, Pipe VARCHAR(32) REFERENCES PIPES(ID) NOT NULL +, Value NUMERIC NOT NULL +); + +CREATE TABLE REACTIONS_TANK +( + Tank VARCHAR(32) REFERENCES TANKS(ID) NOT NULL +, Value NUMERIC NOT NULL +); + +CREATE TABLE REACTIONS_LIMITING_POTENTIAL +( + Value NUMERIC NOT NULL +); + +CREATE TABLE REACTIONS_ROUGHNESS_CORRELATION +( + Value NUMERIC NOT NULL +); diff --git a/script/script/table/create/2.junctions.sql b/script/script/table/create/2.junctions.sql new file mode 100644 index 0000000..42ea2f3 --- /dev/null +++ b/script/script/table/create/2.junctions.sql @@ -0,0 +1,9 @@ +-- [JUNCTIONS] + +CREATE TABLE JUNCTIONS +( + ID VARCHAR(32) PRIMARY KEY REFERENCES _NODE(ID) +, Elevation NUMERIC NOT NULL +, Demand NUMERIC +, Pattern VARCHAR(32) REFERENCES _PATTERN(ID) +); diff --git a/script/script/table/create/20.mixing.sql b/script/script/table/create/20.mixing.sql new file mode 100644 index 0000000..b6675bb --- /dev/null +++ b/script/script/table/create/20.mixing.sql @@ -0,0 +1,10 @@ +-- [MIXING] + +CREATE TYPE MIXING_Model AS ENUM ('MIXED', '2COMP', 'FIFO', 'LIFO'); + +CREATE TABLE MIXING +( + Tank VARCHAR(32) PRIMARY KEY REFERENCES TANKS(ID) +, Model MIXING_Model NOT NULL +, Value NUMERIC +); diff --git a/script/script/table/create/21.times.sql b/script/script/table/create/21.times.sql new file mode 100644 index 0000000..a68e504 --- /dev/null +++ b/script/script/table/create/21.times.sql @@ -0,0 +1,9 @@ +-- [TIMES] + +-- TODO: constraint + +CREATE TABLE TIMES +( + Key TEXT NOT NULL +, Value TEXT NOT NULL +); diff --git a/script/script/table/create/22.report.sql b/script/script/table/create/22.report.sql new file mode 100644 index 0000000..c2435d3 --- /dev/null +++ b/script/script/table/create/22.report.sql @@ -0,0 +1,9 @@ +-- [REPORT] + +-- TODO: constraint + +CREATE TABLE REPORT +( + Key TEXT NOT NULL +, Value TEXT NOT NULL +); diff --git a/script/script/table/create/23.options.sql b/script/script/table/create/23.options.sql new file mode 100644 index 0000000..16d50a4 --- /dev/null +++ b/script/script/table/create/23.options.sql @@ -0,0 +1,9 @@ +-- [OPTIONS] + +-- TODO: constraint + +CREATE TABLE OPTIONS +( + Key TEXT NOT NULL +, Value TEXT NOT NULL +); diff --git a/script/script/table/create/24.coordinates.sql b/script/script/table/create/24.coordinates.sql new file mode 100644 index 0000000..5b6ed6d --- /dev/null +++ b/script/script/table/create/24.coordinates.sql @@ -0,0 +1,10 @@ +-- [COORDINATES] + +CREATE TABLE COORDINATES +( + Node VARCHAR(32) PRIMARY KEY REFERENCES _NODE(ID) +, Coord POINT NOT NULL +); + +CREATE INDEX COORDINATES_SPGIST ON COORDINATES USING SPGIST(Coord); +CREATE INDEX COORDINATES_GIST ON COORDINATES USING GIST(Coord); diff --git a/script/script/table/create/25.vertices.sql b/script/script/table/create/25.vertices.sql new file mode 100644 index 0000000..3f509c6 --- /dev/null +++ b/script/script/table/create/25.vertices.sql @@ -0,0 +1,8 @@ +-- [VERTICES] + +CREATE TABLE VERTICES +( + Link VARCHAR(32) REFERENCES _LINK(ID) NOT NULL +, X NUMERIC NOT NULL +, Y NUMERIC NOT NULL +); diff --git a/script/script/table/create/26.labels.sql b/script/script/table/create/26.labels.sql new file mode 100644 index 0000000..cf95e00 --- /dev/null +++ b/script/script/table/create/26.labels.sql @@ -0,0 +1,9 @@ +-- [LABELS] + +CREATE TABLE LABELS +( + X NUMERIC NOT NULL +, Y NUMERIC NOT NULL +, Label TEXT NOT NULL +, AnchorNode VARCHAR(32) REFERENCES _NODE(ID) +); diff --git a/script/script/table/create/27.backdrop.sql b/script/script/table/create/27.backdrop.sql new file mode 100644 index 0000000..4216368 --- /dev/null +++ b/script/script/table/create/27.backdrop.sql @@ -0,0 +1,6 @@ +-- [BACKDROP] + +CREATE TABLE BACKDROP +( + Content TEXT PRIMARY KEY +); diff --git a/script/script/table/create/28.end.sql b/script/script/table/create/28.end.sql new file mode 100644 index 0000000..3054ad0 --- /dev/null +++ b/script/script/table/create/28.end.sql @@ -0,0 +1 @@ +-- [END] \ No newline at end of file diff --git a/script/script/table/create/3.reservoirs.sql b/script/script/table/create/3.reservoirs.sql new file mode 100644 index 0000000..476c793 --- /dev/null +++ b/script/script/table/create/3.reservoirs.sql @@ -0,0 +1,8 @@ +-- [RESERVOIRS] + +CREATE TABLE RESERVOIRS +( + ID VARCHAR(32) PRIMARY KEY REFERENCES _NODE(ID) +, Head NUMERIC NOT NULL +, Pattern VARCHAR(32) REFERENCES _PATTERN(ID) +); diff --git a/script/script/table/create/4.tanks.sql b/script/script/table/create/4.tanks.sql new file mode 100644 index 0000000..df0bdf4 --- /dev/null +++ b/script/script/table/create/4.tanks.sql @@ -0,0 +1,16 @@ +-- [TANKS] + +CREATE TYPE TANKS_OVERFLOW AS ENUM ('YES', 'NO'); + +CREATE TABLE TANKS +( + ID VARCHAR(32) PRIMARY KEY REFERENCES _NODE(ID) +, Elevation NUMERIC NOT NULL +, InitLevel NUMERIC NOT NULL +, MinLevel NUMERIC NOT NULL +, MaxLevel NUMERIC NOT NULL +, Diameter NUMERIC NOT NULL +, MinVol NUMERIC NOT NULL +, VolCurve VARCHAR(32) REFERENCES _CURVE(ID) +, Overflow TANKS_OVERFLOW +); diff --git a/script/script/table/create/5.pipes.sql b/script/script/table/create/5.pipes.sql new file mode 100644 index 0000000..fb1dc2d --- /dev/null +++ b/script/script/table/create/5.pipes.sql @@ -0,0 +1,15 @@ +-- [PIPES] + +CREATE TYPE PIPES_STATUS AS ENUM ('OPEN', 'CLOSED', 'CV'); + +CREATE TABLE PIPES +( + ID VARCHAR(32) PRIMARY KEY REFERENCES _LINK(ID) +, Node1 VARCHAR(32) REFERENCES _NODE(ID) NOT NULL +, Node2 VARCHAR(32) REFERENCES _NODE(ID) NOT NULL +, Length NUMERIC NOT NULL +, Diameter NUMERIC NOT NULL +, Roughness NUMERIC NOT NULL +, MinorLoss NUMERIC NOT NULL +, Status PIPES_STATUS NOT NULL +); diff --git a/script/script/table/create/6.pumps.sql b/script/script/table/create/6.pumps.sql new file mode 100644 index 0000000..b701708 --- /dev/null +++ b/script/script/table/create/6.pumps.sql @@ -0,0 +1,32 @@ +-- [PUMPS] + +CREATE TABLE PUMPS +( + ID VARCHAR(32) PRIMARY KEY REFERENCES _LINK(ID) +, Node1 VARCHAR(32) REFERENCES _NODE(ID) NOT NULL +, Node2 VARCHAR(32) REFERENCES _NODE(ID) NOT NULL +); + +CREATE TABLE PUMPS_PROPERTY_POWER +( + ID VARCHAR PRIMARY KEY REFERENCES PUMPS(ID) +, Value VARCHAR(32) NOT NULL +); + +CREATE TABLE PUMPS_PROPERTY_SPEED +( + ID VARCHAR PRIMARY KEY REFERENCES PUMPS(ID) +, Value VARCHAR(32) NOT NULL +); + +CREATE TABLE PUMPS_PROPERTY_HEAD +( + ID VARCHAR PRIMARY KEY REFERENCES PUMPS(ID) +, Head VARCHAR(32) REFERENCES _CURVE(ID) NOT NULL +); + +CREATE TABLE PUMPS_PROPERTY_PATTERN +( + ID VARCHAR PRIMARY KEY REFERENCES PUMPS(ID) +, Pattern VARCHAR(32) REFERENCES _PATTERN(ID) NOT NULL +); diff --git a/script/script/table/create/7.valves.sql b/script/script/table/create/7.valves.sql new file mode 100644 index 0000000..7159aac --- /dev/null +++ b/script/script/table/create/7.valves.sql @@ -0,0 +1,14 @@ +-- [VALVES] + +CREATE TYPE VALVES_TYPE AS ENUM ('PRV', 'PSV', 'PBV', 'FCV', 'TCV', 'GPV'); + +CREATE TABLE VALVES +( + ID VARCHAR(32) PRIMARY KEY REFERENCES _LINK(ID) +, Node1 VARCHAR(32) REFERENCES _NODE(ID) NOT NULL +, Node2 VARCHAR(32) REFERENCES _NODE(ID) NOT NULL +, Diameter NUMERIC NOT NULL +, Type VALVES_TYPE NOT NULL +, Setting NUMERIC NOT NULL +, MinorLoss NUMERIC NOT NULL +); diff --git a/script/script/table/create/8.tags.sql b/script/script/table/create/8.tags.sql new file mode 100644 index 0000000..0cc496c --- /dev/null +++ b/script/script/table/create/8.tags.sql @@ -0,0 +1,13 @@ +-- [TAGS] + +CREATE TABLE TAGS_NODE +( + ID VARCHAR(32) PRIMARY KEY REFERENCES _NODE(ID) +, Tag TEXT NOT NULL +); + +CREATE TABLE TAGS_LINK +( + ID VARCHAR(32) PRIMARY KEY REFERENCES _LINK(ID) +, Tag TEXT NOT NULL +); diff --git a/script/script/table/create/9.demands.sql b/script/script/table/create/9.demands.sql new file mode 100644 index 0000000..355354d --- /dev/null +++ b/script/script/table/create/9.demands.sql @@ -0,0 +1,9 @@ +-- [DEMANDS] + +CREATE TABLE DEMANDS +( + Junction VARCHAR(32) REFERENCES JUNCTIONS(ID) NOT NULL +, Demand NUMERIC NOT NULL +, Pattern VARCHAR(32) REFERENCES _PATTERN(ID) +, Category TEXT NOT NULL +); diff --git a/script/script/table/create/namespace.sql b/script/script/table/create/namespace.sql new file mode 100644 index 0000000..fc993ed --- /dev/null +++ b/script/script/table/create/namespace.sql @@ -0,0 +1 @@ +create schema tj; \ No newline at end of file diff --git a/script/script/table/create/operation.sql b/script/script/table/create/operation.sql new file mode 100644 index 0000000..2f105e6 --- /dev/null +++ b/script/script/table/create/operation.sql @@ -0,0 +1,29 @@ +CREATE TABLE OPERATION +( + ID SERIAL PRIMARY KEY +, Redo TEXT NOT NULL +, Undo TEXT NOT NULL +, Parent INTEGER REFERENCES OPERATION(ID) +, Redo_Child INTEGER REFERENCES OPERATION(ID) +); + +INSERT INTO OPERATION (ID, Redo, Undo) VALUES (0, '', ''); + +CREATE TABLE CURRENT_OPERATION +( + ID INTEGER PRIMARY KEY REFERENCES OPERATION(ID) +); + +INSERT INTO CURRENT_OPERATION (ID) VALUES (0); + +CREATE TABLE SNAPSHOT_OPERATION +( + ID INTEGER PRIMARY KEY REFERENCES OPERATION(ID) +, Tag TEXT NOT NULL UNIQUE +); + +CREATE TABLE TRANSACTION_OPERATION +( + ID INTEGER PRIMARY KEY REFERENCES OPERATION(ID) +, STRICT BOOLEAN NOT NULL DEFAULT FALSE +); diff --git a/script/script/table/drop/0.base.sql b/script/script/table/drop/0.base.sql new file mode 100644 index 0000000..3b57bb0 --- /dev/null +++ b/script/script/table/drop/0.base.sql @@ -0,0 +1,11 @@ +DROP TABLE IF EXISTS _PATTERN; + +DROP TABLE IF EXISTS _CURVE; + +DROP TABLE IF EXISTS _LINK; + +DROP TABLE IF EXISTS _NODE; + +DROP TYPE IF EXISTS _LINK_TYPE; + +DROP TYPE IF EXISTS _NODE_TYPE; diff --git a/script/script/table/drop/1.title.sql b/script/script/table/drop/1.title.sql new file mode 100644 index 0000000..7ee6d55 --- /dev/null +++ b/script/script/table/drop/1.title.sql @@ -0,0 +1,3 @@ +-- [TITLE] + +DROP TABLE IF EXISTS TITLE; diff --git a/script/script/table/drop/10.status.sql b/script/script/table/drop/10.status.sql new file mode 100644 index 0000000..322a72f --- /dev/null +++ b/script/script/table/drop/10.status.sql @@ -0,0 +1,13 @@ +-- [STATUS] + +DROP TABLE IF EXISTS STATUS_LINK; + +DROP TABLE IF EXISTS STATUS_VALVE; + +DROP TYPE IF EXISTS STATUS_VALVE_STATUS; + +DROP TABLE IF EXISTS STATUS_PUMP; + +DROP TABLE IF EXISTS STATUS_PIPE; + +DROP TYPE IF EXISTS STATUS_PIPE_PUMP_STATUS; diff --git a/script/script/table/drop/11.patterns.sql b/script/script/table/drop/11.patterns.sql new file mode 100644 index 0000000..fd08d97 --- /dev/null +++ b/script/script/table/drop/11.patterns.sql @@ -0,0 +1,3 @@ +-- [PATTERNS] + +DROP TABLE IF EXISTS PATTERNS; diff --git a/script/script/table/drop/12.curves.sql b/script/script/table/drop/12.curves.sql new file mode 100644 index 0000000..577464e --- /dev/null +++ b/script/script/table/drop/12.curves.sql @@ -0,0 +1,3 @@ +-- [CURVES] + +DROP TABLE IF EXISTS CURVES; diff --git a/script/script/table/drop/13.controls.sql b/script/script/table/drop/13.controls.sql new file mode 100644 index 0000000..476259d --- /dev/null +++ b/script/script/table/drop/13.controls.sql @@ -0,0 +1,9 @@ +-- [CONTROLS] + +DROP TABLE IF EXISTS CONTROLS_3; + +DROP TABLE IF EXISTS CONTROLS_2; + +DROP TABLE IF EXISTS CONTROLS_1; + +DROP TYPE IF EXISTS CONTROLS_1_PREP; diff --git a/script/script/table/drop/14.rules.sql b/script/script/table/drop/14.rules.sql new file mode 100644 index 0000000..84e4fd8 --- /dev/null +++ b/script/script/table/drop/14.rules.sql @@ -0,0 +1,3 @@ +-- [RULES] + +DROP TABLE IF EXISTS RULES; diff --git a/script/script/table/drop/15.energy.sql b/script/script/table/drop/15.energy.sql new file mode 100644 index 0000000..5002d5c --- /dev/null +++ b/script/script/table/drop/15.energy.sql @@ -0,0 +1,9 @@ +-- [ENERGY] + +DROP TABLE IF EXISTS ENERGY_DEMAND_CHARGE; + +DROP TABLE IF EXISTS ENERGY_PUMP; + +DROP TABLE IF EXISTS ENERGY_GLOBAL; + +DROP TYPE IF EXISTS ENERGY_PARAM; diff --git a/script/script/table/drop/16.emitters.sql b/script/script/table/drop/16.emitters.sql new file mode 100644 index 0000000..40a0af8 --- /dev/null +++ b/script/script/table/drop/16.emitters.sql @@ -0,0 +1,3 @@ +-- [EMITTERS] + +DROP TABLE IF EXISTS EMITTERS; diff --git a/script/script/table/drop/17.quality.sql b/script/script/table/drop/17.quality.sql new file mode 100644 index 0000000..b72c290 --- /dev/null +++ b/script/script/table/drop/17.quality.sql @@ -0,0 +1,3 @@ +-- [QUALITY] + +DROP TABLE IF EXISTS QUALITY; diff --git a/script/script/table/drop/18.sources.sql b/script/script/table/drop/18.sources.sql new file mode 100644 index 0000000..0402ffe --- /dev/null +++ b/script/script/table/drop/18.sources.sql @@ -0,0 +1,5 @@ +-- [SOURCES] + +DROP TABLE IF EXISTS SOURCES; + +DROP TYPE IF EXISTS SOURCES_TYPE; diff --git a/script/script/table/drop/19.reactions.sql b/script/script/table/drop/19.reactions.sql new file mode 100644 index 0000000..2f6ba5b --- /dev/null +++ b/script/script/table/drop/19.reactions.sql @@ -0,0 +1,19 @@ +-- [REACTIONS] + +DROP TABLE IF EXISTS REACTIONS_ROUGHNESS_CORRELATION; + +DROP TABLE IF EXISTS REACTIONS_LIMITING_POTENTIAL; + +DROP TABLE IF EXISTS REACTIONS_TANK; + +DROP TABLE IF EXISTS REACTIONS_PIPE; + +DROP TYPE IF EXISTS REACTIONS_PIPE_PARAM; + +DROP TABLE IF EXISTS REACTIONS_GLOBAL; + +DROP TYPE IF EXISTS REACTIONS_GLOBAL_PARAM; + +DROP TABLE IF EXISTS REACTIONS_ORDER; + +DROP TYPE IF EXISTS REACTIONS_ORDER_PARAM; diff --git a/script/script/table/drop/2.junctions.sql b/script/script/table/drop/2.junctions.sql new file mode 100644 index 0000000..ef0a609 --- /dev/null +++ b/script/script/table/drop/2.junctions.sql @@ -0,0 +1,3 @@ +-- [JUNCTIONS] + +DROP TABLE IF EXISTS JUNCTIONS; diff --git a/script/script/table/drop/20.mixing.sql b/script/script/table/drop/20.mixing.sql new file mode 100644 index 0000000..938d554 --- /dev/null +++ b/script/script/table/drop/20.mixing.sql @@ -0,0 +1,5 @@ +-- [MIXING] + +DROP TABLE IF EXISTS MIXING; + +DROP TYPE IF EXISTS MIXING_Model; diff --git a/script/script/table/drop/21.times.sql b/script/script/table/drop/21.times.sql new file mode 100644 index 0000000..f051bd7 --- /dev/null +++ b/script/script/table/drop/21.times.sql @@ -0,0 +1,3 @@ +-- [TIMES] + +DROP TABLE IF EXISTS TIMES; diff --git a/script/script/table/drop/22.report.sql b/script/script/table/drop/22.report.sql new file mode 100644 index 0000000..790684d --- /dev/null +++ b/script/script/table/drop/22.report.sql @@ -0,0 +1,3 @@ +-- [REPORT] + +DROP TABLE IF EXISTS REPORT; diff --git a/script/script/table/drop/23.options.sql b/script/script/table/drop/23.options.sql new file mode 100644 index 0000000..7cc629a --- /dev/null +++ b/script/script/table/drop/23.options.sql @@ -0,0 +1,3 @@ +-- [OPTIONS] + +DROP TABLE IF EXISTS OPTIONS; diff --git a/script/script/table/drop/24.coordinates.sql b/script/script/table/drop/24.coordinates.sql new file mode 100644 index 0000000..04d0465 --- /dev/null +++ b/script/script/table/drop/24.coordinates.sql @@ -0,0 +1,7 @@ +-- [COORDINATES] + +DROP INDEX IF EXISTS COORDINATES_GIST; + +DROP INDEX IF EXISTS COORDINATES_SPGIST; + +DROP TABLE IF EXISTS COORDINATES; diff --git a/script/script/table/drop/25.vertices.sql b/script/script/table/drop/25.vertices.sql new file mode 100644 index 0000000..f74dd3e --- /dev/null +++ b/script/script/table/drop/25.vertices.sql @@ -0,0 +1,3 @@ +-- [VERTICES] + +DROP TABLE IF EXISTS VERTICES; diff --git a/script/script/table/drop/26.labels.sql b/script/script/table/drop/26.labels.sql new file mode 100644 index 0000000..aa1b2b2 --- /dev/null +++ b/script/script/table/drop/26.labels.sql @@ -0,0 +1,3 @@ +-- [LABELS] + +DROP TABLE IF EXISTS LABELS; diff --git a/script/script/table/drop/27.backdrop.sql b/script/script/table/drop/27.backdrop.sql new file mode 100644 index 0000000..408bb85 --- /dev/null +++ b/script/script/table/drop/27.backdrop.sql @@ -0,0 +1,3 @@ +-- [BACKDROP] + +DROP TABLE IF EXISTS BACKDROP; diff --git a/script/script/table/drop/28.end.sql b/script/script/table/drop/28.end.sql new file mode 100644 index 0000000..3054ad0 --- /dev/null +++ b/script/script/table/drop/28.end.sql @@ -0,0 +1 @@ +-- [END] \ No newline at end of file diff --git a/script/script/table/drop/3.reservoirs.sql b/script/script/table/drop/3.reservoirs.sql new file mode 100644 index 0000000..9864c18 --- /dev/null +++ b/script/script/table/drop/3.reservoirs.sql @@ -0,0 +1,3 @@ +-- [RESERVOIRS] + +DROP TABLE IF EXISTS RESERVOIRS; diff --git a/script/script/table/drop/4.tanks.sql b/script/script/table/drop/4.tanks.sql new file mode 100644 index 0000000..da0487d --- /dev/null +++ b/script/script/table/drop/4.tanks.sql @@ -0,0 +1,5 @@ +-- [TANKS] + +DROP TABLE IF EXISTS TANKS; + +DROP TYPE IF EXISTS TANKS_OVERFLOW; diff --git a/script/script/table/drop/5.pipes.sql b/script/script/table/drop/5.pipes.sql new file mode 100644 index 0000000..1e23612 --- /dev/null +++ b/script/script/table/drop/5.pipes.sql @@ -0,0 +1,5 @@ +-- [PIPES] + +DROP TABLE IF EXISTS PIPES; + +DROP TYPE IF EXISTS PIPES_STATUS; diff --git a/script/script/table/drop/6.pumps.sql b/script/script/table/drop/6.pumps.sql new file mode 100644 index 0000000..5ac9656 --- /dev/null +++ b/script/script/table/drop/6.pumps.sql @@ -0,0 +1,11 @@ +-- [PUMPS] + +DROP TABLE IF EXISTS PUMPS_PROPERTY_PATTERN; + +DROP TABLE IF EXISTS PUMPS_PROPERTY_HEAD; + +DROP TABLE IF EXISTS PUMPS_PROPERTY_SPEED; + +DROP TABLE IF EXISTS PUMPS_PROPERTY_POWER; + +DROP TABLE IF EXISTS PUMPS; diff --git a/script/script/table/drop/7.valves.sql b/script/script/table/drop/7.valves.sql new file mode 100644 index 0000000..c95b423 --- /dev/null +++ b/script/script/table/drop/7.valves.sql @@ -0,0 +1,5 @@ +-- [VALVES] + +DROP TABLE IF EXISTS VALVES; + +DROP TYPE IF EXISTS VALVES_TYPE; diff --git a/script/script/table/drop/8.tags.sql b/script/script/table/drop/8.tags.sql new file mode 100644 index 0000000..df8e3d1 --- /dev/null +++ b/script/script/table/drop/8.tags.sql @@ -0,0 +1,5 @@ +-- [TAGS] + +DROP TABLE IF EXISTS TAGS_LINK; + +DROP TABLE IF EXISTS TAGS_NODE; diff --git a/script/script/table/drop/9.demands.sql b/script/script/table/drop/9.demands.sql new file mode 100644 index 0000000..ebe0209 --- /dev/null +++ b/script/script/table/drop/9.demands.sql @@ -0,0 +1,3 @@ +-- [DEMANDS] + +DROP TABLE IF EXISTS DEMANDS; diff --git a/script/script/table/drop/namespace.sql b/script/script/table/drop/namespace.sql new file mode 100644 index 0000000..effb087 --- /dev/null +++ b/script/script/table/drop/namespace.sql @@ -0,0 +1 @@ +drop schema if exists tj; \ No newline at end of file diff --git a/script/script/table/drop/operation.sql b/script/script/table/drop/operation.sql new file mode 100644 index 0000000..998ee2f --- /dev/null +++ b/script/script/table/drop/operation.sql @@ -0,0 +1,7 @@ +DROP TABLE IF EXISTS TRANSACTION_OPERATION; + +DROP TABLE IF EXISTS SNAPSHOT_OPERATION; + +DROP TABLE IF EXISTS CURRENT_OPERATION; + +DROP TABLE IF EXISTS OPERATION;