diff --git a/script/script/table/create/0.base.sql b/script/script/table/create/0.base.sql index 5ae4026..91b48c0 100644 --- a/script/script/table/create/0.base.sql +++ b/script/script/table/create/0.base.sql @@ -1,6 +1,16 @@ -create type tj.node_type as enum ('junction', 'reservoir', 'tank'); +create type tj.node_type as enum +( + 'junction' +, 'reservoir' +, 'tank' +); -create type tj.link_type as enum ('pipe', 'pump', 'valve'); +create type tj.link_type as enum +( + 'pipe' +, 'pump' +, 'valve' +); create table tj.node ( diff --git a/script/script/table/create/1.title.sql b/script/script/table/create/1.title.sql index c00e981..8ba6426 100644 --- a/script/script/table/create/1.title.sql +++ b/script/script/table/create/1.title.sql @@ -1,8 +1,8 @@ --- [TITLE] +-- [title] -CREATE TABLE TITLE +create table tj.title ( - Value TEXT + value text ); -INSERT INTO TITLE (Value) VALUES (''); +insert into tj.title (value) values (''); diff --git a/script/script/table/create/10.status.sql b/script/script/table/create/10.status.sql index 34da1f7..c736c76 100644 --- a/script/script/table/create/10.status.sql +++ b/script/script/table/create/10.status.sql @@ -1,29 +1,33 @@ --- [STATUS] +-- [status] -CREATE TYPE STATUS_PIPE_PUMP_STATUS AS ENUM ('OPEN', 'CLOSED'); - -CREATE TABLE STATUS_PIPE +create type tj.status_pipe_pump_status as enum ( - ID VARCHAR(32) PRIMARY KEY REFERENCES PIPES(ID) -, Status STATUS_PIPE_PUMP_STATUS NOT NULL + 'open' +, 'closed' ); -CREATE TABLE STATUS_PUMP +create table tj.status_pipe ( - ID VARCHAR(32) PRIMARY KEY REFERENCES PUMPS(ID) -, Status STATUS_PIPE_PUMP_STATUS NOT NULL + id varchar(32) primary key references tj.pipes(id) +, status tj.status_pipe_pump_status not null ); -CREATE TYPE STATUS_VALVE_STATUS AS ENUM ('OPEN', 'CLOSED', 'ACTIVE'); - -CREATE TABLE STATUS_VALVE +create table tj.status_pump ( - ID VARCHAR(32) PRIMARY KEY REFERENCES VALVES(ID) -, Status STATUS_VALVE_STATUS NOT NULL + id varchar(32) primary key references tj.pumps(id) +, status tj.status_pipe_pump_status not null ); -CREATE TABLE STATUS_LINK +create type tj.status_valve_status as enum ('open', 'closed', 'active'); + +create table tj.status_valve ( - ID VARCHAR(32) PRIMARY KEY REFERENCES _LINK(ID) -, Setting NUMERIC NOT NULL + id varchar(32) primary key references tj.valves(id) +, status tj.status_valve_status not null +); + +create table tj.status_link +( + id varchar(32) primary key references tj.link(id) +, setting numeric not null ); diff --git a/script/script/table/create/11.patterns.sql b/script/script/table/create/11.patterns.sql index dfb23b0..8cd9ad6 100644 --- a/script/script/table/create/11.patterns.sql +++ b/script/script/table/create/11.patterns.sql @@ -1,7 +1,7 @@ --- [PATTERNS] +-- [patterns] -CREATE TABLE PATTERNS +create table tj.patterns ( - ID VARCHAR(32) REFERENCES _PATTERN(ID) NOT NULL -, Multipliers NUMERIC NOT NULL + id varchar(32) references tj.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 index ac2460e..2467450 100644 --- a/script/script/table/create/12.curves.sql +++ b/script/script/table/create/12.curves.sql @@ -1,8 +1,8 @@ --- [CURVES] +-- [curves] -CREATE TABLE CURVES +create table tj.curves ( - ID VARCHAR(32) REFERENCES _CURVE(ID) NOT NULL -, X NUMERIC NOT NULL -, Y NUMERIC NOT NULL + id varchar(32) references tj.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 index aa107eb..ab34bb0 100644 --- a/script/script/table/create/13.controls.sql +++ b/script/script/table/create/13.controls.sql @@ -1,30 +1,30 @@ --- [CONTROLS] +-- [controls] -CREATE TYPE CONTROLS_1_PREP AS ENUM ('ABOVE', 'BELOW'); +create type tj.controls_1_prep as enum ('above', 'below'); --- LINK linkID status IF NODE nodeID ABOVE / BELOW value -CREATE TABLE CONTROLS_1 +-- link linkid status if node nodeid above / below value +create table tj.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 + linkid varchar(32) primary key references tj.link(id) +, status text not null -- open / closed, a pump speed setting, or a control valve setting +, nodeid varchar(32) references tj.node(id) not null +, prep tj.controls_1_prep not null +, value numeric not null ); --- LINK linkID status AT TIME time -CREATE TABLE CONTROLS_2 +-- link linkid status at time time +create table tj.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 + linkid varchar(32) primary key references tj.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 +-- link linkid status at clocktime clocktime am / pm +create table tj.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 + linkid varchar(32) primary key references tj.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 index 7d288ca..617da6b 100644 --- a/script/script/table/create/14.rules.sql +++ b/script/script/table/create/14.rules.sql @@ -1,6 +1,6 @@ --- [RULES] +-- [rules] -CREATE TABLE RULES +create table tj.rules ( - Content TEXT PRIMARY KEY + content text primary key ); diff --git a/script/script/table/create/15.energy.sql b/script/script/table/create/15.energy.sql index a73a3db..1544968 100644 --- a/script/script/table/create/15.energy.sql +++ b/script/script/table/create/15.energy.sql @@ -1,24 +1,29 @@ --- [ENERGY] +-- [energy] -CREATE TYPE ENERGY_PARAM AS ENUM ('PRICE', 'PATTERN', 'EFFIC'); - --- GLOBAL PRICE / PATTERN / EFFIC value -CREATE TABLE ENERGY_GLOBAL +create type tj.energy_param as enum ( - Param ENERGY_PARAM NOT NULL -, Value NUMERIC NOT NULL + 'price' +, 'pattern' +, 'effic' ); --- PUMP pumpID PRICE / PATTERN / EFFIC value -CREATE TABLE ENERGY_PUMP +-- global price / pattern / effic value +create table tj.energy_global ( - ID VARCHAR(32) REFERENCES PUMPS(ID) NOT NULL -, Param ENERGY_PARAM NOT NULL -, Value NUMERIC NOT NULL + param tj.energy_param not null +, value numeric not null ); --- DEMAND CHARGE value -CREATE TABLE ENERGY_DEMAND_CHARGE +-- pump pumpid price / pattern / effic value +create table tj.energy_pump ( - Value NUMERIC NOT NULL + id varchar(32) references tj.pumps(id) not null +, param tj.energy_param not null +, value numeric not null +); + +-- demand charge value +create table tj.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 index b1fe8b4..448b9e1 100644 --- a/script/script/table/create/16.emitters.sql +++ b/script/script/table/create/16.emitters.sql @@ -1,7 +1,7 @@ --- [EMITTERS] +-- [emitters] -CREATE TABLE EMITTERS +create table tj.emitters ( - Junction VARCHAR(32) PRIMARY KEY REFERENCES JUNCTIONS(ID) -, Coefficient NUMERIC NOT NULL + junction varchar(32) primary key references tj.junctions(id) +, coefficient numeric not null ); diff --git a/script/script/table/create/17.quality.sql b/script/script/table/create/17.quality.sql index 939e309..e972b30 100644 --- a/script/script/table/create/17.quality.sql +++ b/script/script/table/create/17.quality.sql @@ -1,7 +1,7 @@ --- [QUALITY] +-- [quality] -CREATE TABLE QUALITY +create table tj.quality ( - Node VARCHAR(32) PRIMARY KEY REFERENCES _NODE(ID) -, InitialQual NUMERIC NOT NULL + node varchar(32) primary key references tj.node(id) +, initialqual numeric not null ); diff --git a/script/script/table/create/18.sources.sql b/script/script/table/create/18.sources.sql index 1c2ec64..25d480d 100644 --- a/script/script/table/create/18.sources.sql +++ b/script/script/table/create/18.sources.sql @@ -1,11 +1,17 @@ --- [SOURCES] +-- [sources] -CREATE TYPE SOURCES_TYPE AS ENUM ('CONCEN', 'MASS', 'FLOWPACED', 'SETPOINT'); - -CREATE TABLE SOURCES +create type tj.sources_type as enum ( - Node VARCHAR(32) PRIMARY KEY REFERENCES _NODE(ID) -, Type SOURCES_TYPE NOT NULL -, Strength NUMERIC NOT NULL -, TimePattern VARCHAR(32) REFERENCES _PATTERN(ID) + 'concen' +, 'mass' +, 'flowpaced' +, 'setpoint' +); + +create table tj.sources +( + node varchar(32) primary key references tj.node(id) +, type tj.sources_type not null +, strength numeric not null +, timepattern varchar(32) references tj.pattern(id) ); diff --git a/script/script/table/create/19.reactions.sql b/script/script/table/create/19.reactions.sql index 0d8d13b..7ddab5d 100644 --- a/script/script/table/create/19.reactions.sql +++ b/script/script/table/create/19.reactions.sql @@ -1,42 +1,55 @@ --- [REACTIONS] +-- [reactions] -CREATE TYPE REACTIONS_ORDER_PARAM AS ENUM ('BULK', 'WALL', 'TANK'); - -CREATE TABLE REACTIONS_ORDER +create type tj.reactions_order_param as enum ( - Key REACTIONS_ORDER_PARAM NOT NULL -, Value NUMERIC NOT NULL + 'bulk' +, 'wall' +, 'tank' ); -CREATE TYPE REACTIONS_GLOBAL_PARAM AS ENUM ('BULK', 'WALL'); - -CREATE TABLE REACTIONS_GLOBAL +create table tj.reactions_order ( - Key REACTIONS_GLOBAL_PARAM NOT NULL -, Value NUMERIC NOT NULL + key tj.reactions_order_param not null +, value numeric not null ); -CREATE TYPE REACTIONS_PIPE_PARAM AS ENUM ('BULK', 'WALL'); - -CREATE TABLE REACTIONS_PIPE +create type tj.reactions_global_param as enum ( - Key REACTIONS_PIPE_PARAM NOT NULL -, Pipe VARCHAR(32) REFERENCES PIPES(ID) NOT NULL -, Value NUMERIC NOT NULL + 'bulk' +, 'wall' ); -CREATE TABLE REACTIONS_TANK +create table tj.reactions_global ( - Tank VARCHAR(32) REFERENCES TANKS(ID) NOT NULL -, Value NUMERIC NOT NULL + key tj.reactions_global_param not null +, value numeric not null ); -CREATE TABLE REACTIONS_LIMITING_POTENTIAL +create type tj.reactions_pipe_param as enum ( - Value NUMERIC NOT NULL + 'bulk' +, 'wall' ); -CREATE TABLE REACTIONS_ROUGHNESS_CORRELATION +create table tj.reactions_pipe ( - Value NUMERIC NOT NULL + key tj.reactions_pipe_param not null +, pipe varchar(32) references tj.pipes(id) not null +, value numeric not null +); + +create table tj.reactions_tank +( + tank varchar(32) references tj.tanks(id) not null +, value numeric not null +); + +create table tj.reactions_limiting_potential +( + value numeric not null +); + +create table tj.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 index 42ea2f3..6397246 100644 --- a/script/script/table/create/2.junctions.sql +++ b/script/script/table/create/2.junctions.sql @@ -1,9 +1,9 @@ --- [JUNCTIONS] +-- [junctions] -CREATE TABLE JUNCTIONS +create table tj.junctions ( - ID VARCHAR(32) PRIMARY KEY REFERENCES _NODE(ID) -, Elevation NUMERIC NOT NULL -, Demand NUMERIC -, Pattern VARCHAR(32) REFERENCES _PATTERN(ID) + id varchar(32) primary key references tj.node(id) +, elevation numeric not null +, demand numeric +, pattern varchar(32) references tj.pattern(id) ); diff --git a/script/script/table/create/20.mixing.sql b/script/script/table/create/20.mixing.sql index b6675bb..65acf21 100644 --- a/script/script/table/create/20.mixing.sql +++ b/script/script/table/create/20.mixing.sql @@ -1,10 +1,16 @@ --- [MIXING] +-- [mixing] -CREATE TYPE MIXING_Model AS ENUM ('MIXED', '2COMP', 'FIFO', 'LIFO'); - -CREATE TABLE MIXING +create type tj.mixing_model as enum ( - Tank VARCHAR(32) PRIMARY KEY REFERENCES TANKS(ID) -, Model MIXING_Model NOT NULL -, Value NUMERIC + 'mixed' +, '2comp' +, 'fifo' +, 'lifo' +); + +create table tj.mixing +( + tank varchar(32) primary key references tj.tanks(id) +, model tj.mixing_model not null +, value numeric ); diff --git a/script/script/table/create/21.times.sql b/script/script/table/create/21.times.sql index a68e504..f66ce2d 100644 --- a/script/script/table/create/21.times.sql +++ b/script/script/table/create/21.times.sql @@ -1,9 +1,9 @@ --- [TIMES] +-- [times] --- TODO: constraint +-- todo: constraint -CREATE TABLE TIMES +create table tj.times ( - Key TEXT NOT NULL -, Value TEXT NOT NULL + 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 index c2435d3..4434a05 100644 --- a/script/script/table/create/22.report.sql +++ b/script/script/table/create/22.report.sql @@ -1,9 +1,9 @@ --- [REPORT] +-- [report] --- TODO: constraint +-- todo: constraint -CREATE TABLE REPORT +create table tj.report ( - Key TEXT NOT NULL -, Value TEXT NOT NULL + 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 index 16d50a4..cab34f4 100644 --- a/script/script/table/create/23.options.sql +++ b/script/script/table/create/23.options.sql @@ -1,9 +1,9 @@ --- [OPTIONS] +-- [options] --- TODO: constraint +-- todo: constraint -CREATE TABLE OPTIONS +create table tj.options ( - Key TEXT NOT NULL -, Value TEXT NOT NULL + 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 index 5b6ed6d..4804896 100644 --- a/script/script/table/create/24.coordinates.sql +++ b/script/script/table/create/24.coordinates.sql @@ -1,10 +1,10 @@ --- [COORDINATES] +-- [coordinates] -CREATE TABLE COORDINATES +create table tj.coordinates ( - Node VARCHAR(32) PRIMARY KEY REFERENCES _NODE(ID) -, Coord POINT NOT NULL + node varchar(32) primary key references tj.node(id) +, coord point not null ); -CREATE INDEX COORDINATES_SPGIST ON COORDINATES USING SPGIST(Coord); -CREATE INDEX COORDINATES_GIST ON COORDINATES USING GIST(Coord); +create index tj.coordinates_spgist on tj.coordinates using spgist(coord); +create index tj.coordinates_gist on tj.coordinates using gist(coord); diff --git a/script/script/table/create/25.vertices.sql b/script/script/table/create/25.vertices.sql index 3f509c6..7b4d403 100644 --- a/script/script/table/create/25.vertices.sql +++ b/script/script/table/create/25.vertices.sql @@ -1,8 +1,8 @@ --- [VERTICES] +-- [vertices] -CREATE TABLE VERTICES +create table tj.vertices ( - Link VARCHAR(32) REFERENCES _LINK(ID) NOT NULL -, X NUMERIC NOT NULL -, Y NUMERIC NOT NULL + link varchar(32) references tj.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 index cf95e00..3b41fce 100644 --- a/script/script/table/create/26.labels.sql +++ b/script/script/table/create/26.labels.sql @@ -1,9 +1,9 @@ --- [LABELS] +-- [labels] -CREATE TABLE LABELS +create table tj.labels ( - X NUMERIC NOT NULL -, Y NUMERIC NOT NULL -, Label TEXT NOT NULL -, AnchorNode VARCHAR(32) REFERENCES _NODE(ID) + x numeric not null +, y numeric not null +, label text not null +, anchornode varchar(32) references tj.node(id) ); diff --git a/script/script/table/create/27.backdrop.sql b/script/script/table/create/27.backdrop.sql index 4216368..aea6d3b 100644 --- a/script/script/table/create/27.backdrop.sql +++ b/script/script/table/create/27.backdrop.sql @@ -1,6 +1,6 @@ --- [BACKDROP] +-- [backdrop] -CREATE TABLE BACKDROP +create table tj.backdrop ( - Content TEXT PRIMARY KEY + content text primary key ); diff --git a/script/script/table/create/3.reservoirs.sql b/script/script/table/create/3.reservoirs.sql index 476c793..e7562ec 100644 --- a/script/script/table/create/3.reservoirs.sql +++ b/script/script/table/create/3.reservoirs.sql @@ -1,8 +1,8 @@ --- [RESERVOIRS] +-- [reservoirs] -CREATE TABLE RESERVOIRS +create table tj.reservoirs ( - ID VARCHAR(32) PRIMARY KEY REFERENCES _NODE(ID) -, Head NUMERIC NOT NULL -, Pattern VARCHAR(32) REFERENCES _PATTERN(ID) + id varchar(32) primary key references tj.node(id) +, head numeric not null +, pattern varchar(32) references tj.pattern(id) ); diff --git a/script/script/table/create/4.tanks.sql b/script/script/table/create/4.tanks.sql index df0bdf4..5a9a815 100644 --- a/script/script/table/create/4.tanks.sql +++ b/script/script/table/create/4.tanks.sql @@ -1,16 +1,20 @@ --- [TANKS] +-- [tanks] -CREATE TYPE TANKS_OVERFLOW AS ENUM ('YES', 'NO'); - -CREATE TABLE TANKS +create type tj.tanks_overflow as enum ( - 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 + 'yes' +, 'no' +); + +create table tj.tanks +( + id varchar(32) primary key references tj.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 tj.curve(id) +, overflow tj.tanks_overflow ); diff --git a/script/script/table/create/5.pipes.sql b/script/script/table/create/5.pipes.sql index fb1dc2d..d7ec73e 100644 --- a/script/script/table/create/5.pipes.sql +++ b/script/script/table/create/5.pipes.sql @@ -1,15 +1,20 @@ --- [PIPES] +-- [pipes] -CREATE TYPE PIPES_STATUS AS ENUM ('OPEN', 'CLOSED', 'CV'); - -CREATE TABLE PIPES +create type tj.pipes_status as enum ( - 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 + 'open' +, 'closed' +, 'cv' +); + +create table tj.pipes +( + id varchar(32) primary key references tj.link(id) +, node1 varchar(32) references tj.node(id) not null +, node2 varchar(32) references tj.node(id) not null +, length numeric not null +, diameter numeric not null +, roughness numeric not null +, minorloss numeric not null +, status tj.pipes_status not null ); diff --git a/script/script/table/create/6.pumps.sql b/script/script/table/create/6.pumps.sql index b701708..0f5b0cf 100644 --- a/script/script/table/create/6.pumps.sql +++ b/script/script/table/create/6.pumps.sql @@ -1,32 +1,32 @@ --- [PUMPS] +-- [pumps] -CREATE TABLE PUMPS +create table tj.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 + id varchar(32) primary key references tj.link(id) +, node1 varchar(32) references tj.node(id) not null +, node2 varchar(32) references tj.node(id) not null ); -CREATE TABLE PUMPS_PROPERTY_POWER +create table tj.pumps_property_power ( - ID VARCHAR PRIMARY KEY REFERENCES PUMPS(ID) -, Value VARCHAR(32) NOT NULL + id varchar primary key references tj.pumps(id) +, value varchar(32) not null ); -CREATE TABLE PUMPS_PROPERTY_SPEED +create table tj.pumps_property_speed ( - ID VARCHAR PRIMARY KEY REFERENCES PUMPS(ID) -, Value VARCHAR(32) NOT NULL + id varchar primary key references tj.pumps(id) +, value varchar(32) not null ); -CREATE TABLE PUMPS_PROPERTY_HEAD +create table tj.pumps_property_head ( - ID VARCHAR PRIMARY KEY REFERENCES PUMPS(ID) -, Head VARCHAR(32) REFERENCES _CURVE(ID) NOT NULL + id varchar primary key references tj.pumps(id) +, head varchar(32) references tj.curve(id) not null ); -CREATE TABLE PUMPS_PROPERTY_PATTERN +create table tj.pumps_property_pattern ( - ID VARCHAR PRIMARY KEY REFERENCES PUMPS(ID) -, Pattern VARCHAR(32) REFERENCES _PATTERN(ID) NOT NULL + id varchar primary key references tj.pumps(id) +, pattern varchar(32) references tj.pattern(id) not null ); diff --git a/script/script/table/create/7.valves.sql b/script/script/table/create/7.valves.sql index 7159aac..5aa584d 100644 --- a/script/script/table/create/7.valves.sql +++ b/script/script/table/create/7.valves.sql @@ -1,14 +1,22 @@ --- [VALVES] +-- [valves] -CREATE TYPE VALVES_TYPE AS ENUM ('PRV', 'PSV', 'PBV', 'FCV', 'TCV', 'GPV'); - -CREATE TABLE VALVES +create type tj.valves_type as enum ( - 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 + 'prv' +, 'psv' +, 'pbv' +, 'fcv' +, 'tcv' +, 'gpv' +); + +create table tj.valves +( + id varchar(32) primary key references tj.link(id) +, node1 varchar(32) references tj.node(id) not null +, node2 varchar(32) references tj.node(id) not null +, diameter numeric not null +, type tj.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 index 0cc496c..d98132c 100644 --- a/script/script/table/create/8.tags.sql +++ b/script/script/table/create/8.tags.sql @@ -1,13 +1,13 @@ --- [TAGS] +-- [tags] -CREATE TABLE TAGS_NODE +create table tj.tags_node ( - ID VARCHAR(32) PRIMARY KEY REFERENCES _NODE(ID) -, Tag TEXT NOT NULL + id varchar(32) primary key references tj.node(id) +, tag text not null ); -CREATE TABLE TAGS_LINK +create table tj.tags_link ( - ID VARCHAR(32) PRIMARY KEY REFERENCES _LINK(ID) -, Tag TEXT NOT NULL + id varchar(32) primary key references tj.link(id) +, tag text not null ); diff --git a/script/script/table/create/9.demands.sql b/script/script/table/create/9.demands.sql index 355354d..e908227 100644 --- a/script/script/table/create/9.demands.sql +++ b/script/script/table/create/9.demands.sql @@ -1,9 +1,9 @@ --- [DEMANDS] +-- [demands] -CREATE TABLE DEMANDS +create table tj.demands ( - Junction VARCHAR(32) REFERENCES JUNCTIONS(ID) NOT NULL -, Demand NUMERIC NOT NULL -, Pattern VARCHAR(32) REFERENCES _PATTERN(ID) -, Category TEXT NOT NULL + junction varchar(32) references tj.junctions(id) not null +, demand numeric not null +, pattern varchar(32) references tj.pattern(id) +, category text not null ); diff --git a/script/script/table/create/operation.sql b/script/script/table/create/operation.sql index 2f105e6..524ef9e 100644 --- a/script/script/table/create/operation.sql +++ b/script/script/table/create/operation.sql @@ -1,29 +1,29 @@ -CREATE TABLE OPERATION +create table tj.operation ( - ID SERIAL PRIMARY KEY -, Redo TEXT NOT NULL -, Undo TEXT NOT NULL -, Parent INTEGER REFERENCES OPERATION(ID) -, Redo_Child INTEGER REFERENCES OPERATION(ID) + id serial primary key +, redo text not null +, undo text not null +, parent integer references tj.operation(id) +, redo_child integer references tj.operation(id) ); -INSERT INTO OPERATION (ID, Redo, Undo) VALUES (0, '', ''); +insert into tj.operation (id, redo, undo) values (0, '', ''); -CREATE TABLE CURRENT_OPERATION +create table tj.current_operation ( - ID INTEGER PRIMARY KEY REFERENCES OPERATION(ID) + id integer primary key references tj.operation(id) ); -INSERT INTO CURRENT_OPERATION (ID) VALUES (0); +insert into tj.current_operation (id) values (0); -CREATE TABLE SNAPSHOT_OPERATION +create table tj.snapshot_operation ( - ID INTEGER PRIMARY KEY REFERENCES OPERATION(ID) -, Tag TEXT NOT NULL UNIQUE + id integer primary key references tj.operation(id) +, tag text not null unique ); -CREATE TABLE TRANSACTION_OPERATION +create table tj.transaction_operation ( - ID INTEGER PRIMARY KEY REFERENCES OPERATION(ID) -, STRICT BOOLEAN NOT NULL DEFAULT FALSE + id integer primary key references tj.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 index 3b57bb0..41c4f41 100644 --- a/script/script/table/drop/0.base.sql +++ b/script/script/table/drop/0.base.sql @@ -1,11 +1,11 @@ -DROP TABLE IF EXISTS _PATTERN; +drop table if exists tj.pattern; -DROP TABLE IF EXISTS _CURVE; +drop table if exists tj.curve; -DROP TABLE IF EXISTS _LINK; +drop table if exists tj.link; -DROP TABLE IF EXISTS _NODE; +drop table if exists tj.node; -DROP TYPE IF EXISTS _LINK_TYPE; +drop type if exists tj.link_type; -DROP TYPE IF EXISTS _NODE_TYPE; +drop type if exists tj.node_type; diff --git a/script/script/table/drop/1.title.sql b/script/script/table/drop/1.title.sql index 7ee6d55..a03e80a 100644 --- a/script/script/table/drop/1.title.sql +++ b/script/script/table/drop/1.title.sql @@ -1,3 +1,3 @@ --- [TITLE] +-- [title] -DROP TABLE IF EXISTS TITLE; +drop table if exists tj.title; diff --git a/script/script/table/drop/10.status.sql b/script/script/table/drop/10.status.sql index 322a72f..232ca4d 100644 --- a/script/script/table/drop/10.status.sql +++ b/script/script/table/drop/10.status.sql @@ -1,13 +1,13 @@ --- [STATUS] +-- [status] -DROP TABLE IF EXISTS STATUS_LINK; +drop table if exists tj.status_link; -DROP TABLE IF EXISTS STATUS_VALVE; +drop table if exists tj.status_valve; -DROP TYPE IF EXISTS STATUS_VALVE_STATUS; +drop type if exists tj.status_valve_status; -DROP TABLE IF EXISTS STATUS_PUMP; +drop table if exists tj.status_pump; -DROP TABLE IF EXISTS STATUS_PIPE; +drop table if exists tj.status_pipe; -DROP TYPE IF EXISTS STATUS_PIPE_PUMP_STATUS; +drop type if exists tj.status_pipe_pump_status; diff --git a/script/script/table/drop/11.patterns.sql b/script/script/table/drop/11.patterns.sql index fd08d97..5fb2b47 100644 --- a/script/script/table/drop/11.patterns.sql +++ b/script/script/table/drop/11.patterns.sql @@ -1,3 +1,3 @@ --- [PATTERNS] +-- [patterns] -DROP TABLE IF EXISTS PATTERNS; +drop table if exists tj.patterns; diff --git a/script/script/table/drop/12.curves.sql b/script/script/table/drop/12.curves.sql index 577464e..4874ee8 100644 --- a/script/script/table/drop/12.curves.sql +++ b/script/script/table/drop/12.curves.sql @@ -1,3 +1,3 @@ --- [CURVES] +-- [curves] -DROP TABLE IF EXISTS CURVES; +drop table if exists tj.curves; diff --git a/script/script/table/drop/13.controls.sql b/script/script/table/drop/13.controls.sql index 476259d..f6c0502 100644 --- a/script/script/table/drop/13.controls.sql +++ b/script/script/table/drop/13.controls.sql @@ -1,9 +1,9 @@ --- [CONTROLS] +-- [controls] -DROP TABLE IF EXISTS CONTROLS_3; +drop table if exists tj.controls_3; -DROP TABLE IF EXISTS CONTROLS_2; +drop table if exists tj.controls_2; -DROP TABLE IF EXISTS CONTROLS_1; +drop table if exists tj.controls_1; -DROP TYPE IF EXISTS CONTROLS_1_PREP; +drop type if exists tj.controls_1_prep; diff --git a/script/script/table/drop/14.rules.sql b/script/script/table/drop/14.rules.sql index 84e4fd8..a920e6a 100644 --- a/script/script/table/drop/14.rules.sql +++ b/script/script/table/drop/14.rules.sql @@ -1,3 +1,3 @@ --- [RULES] +-- [rules] -DROP TABLE IF EXISTS RULES; +drop table if exists tj.rules; diff --git a/script/script/table/drop/15.energy.sql b/script/script/table/drop/15.energy.sql index 5002d5c..abf2e4a 100644 --- a/script/script/table/drop/15.energy.sql +++ b/script/script/table/drop/15.energy.sql @@ -1,9 +1,9 @@ --- [ENERGY] +-- [energy] -DROP TABLE IF EXISTS ENERGY_DEMAND_CHARGE; +drop table if exists tj.energy_demand_charge; -DROP TABLE IF EXISTS ENERGY_PUMP; +drop table if exists tj.energy_pump; -DROP TABLE IF EXISTS ENERGY_GLOBAL; +drop table if exists tj.energy_global; -DROP TYPE IF EXISTS ENERGY_PARAM; +drop type if exists tj.energy_param; diff --git a/script/script/table/drop/16.emitters.sql b/script/script/table/drop/16.emitters.sql index 40a0af8..ec23cd3 100644 --- a/script/script/table/drop/16.emitters.sql +++ b/script/script/table/drop/16.emitters.sql @@ -1,3 +1,3 @@ --- [EMITTERS] +-- [emitters] -DROP TABLE IF EXISTS EMITTERS; +drop table if exists tj.emitters; diff --git a/script/script/table/drop/17.quality.sql b/script/script/table/drop/17.quality.sql index b72c290..673cd2f 100644 --- a/script/script/table/drop/17.quality.sql +++ b/script/script/table/drop/17.quality.sql @@ -1,3 +1,3 @@ --- [QUALITY] +-- [quality] -DROP TABLE IF EXISTS QUALITY; +drop table if exists tj.quality; diff --git a/script/script/table/drop/18.sources.sql b/script/script/table/drop/18.sources.sql index 0402ffe..e9487c8 100644 --- a/script/script/table/drop/18.sources.sql +++ b/script/script/table/drop/18.sources.sql @@ -1,5 +1,5 @@ --- [SOURCES] +-- [sources] -DROP TABLE IF EXISTS SOURCES; +drop table if exists tj.sources; -DROP TYPE IF EXISTS SOURCES_TYPE; +drop type if exists tj.sources_type; diff --git a/script/script/table/drop/19.reactions.sql b/script/script/table/drop/19.reactions.sql index 2f6ba5b..0dff3f0 100644 --- a/script/script/table/drop/19.reactions.sql +++ b/script/script/table/drop/19.reactions.sql @@ -1,19 +1,19 @@ --- [REACTIONS] +-- [reactions] -DROP TABLE IF EXISTS REACTIONS_ROUGHNESS_CORRELATION; +drop table if exists tj.reactions_roughness_correlation; -DROP TABLE IF EXISTS REACTIONS_LIMITING_POTENTIAL; +drop table if exists tj.reactions_limiting_potential; -DROP TABLE IF EXISTS REACTIONS_TANK; +drop table if exists tj.reactions_tank; -DROP TABLE IF EXISTS REACTIONS_PIPE; +drop table if exists tj.reactions_pipe; -DROP TYPE IF EXISTS REACTIONS_PIPE_PARAM; +drop type if exists tj.reactions_pipe_param; -DROP TABLE IF EXISTS REACTIONS_GLOBAL; +drop table if exists tj.reactions_global; -DROP TYPE IF EXISTS REACTIONS_GLOBAL_PARAM; +drop type if exists tj.reactions_global_param; -DROP TABLE IF EXISTS REACTIONS_ORDER; +drop table if exists tj.reactions_order; -DROP TYPE IF EXISTS REACTIONS_ORDER_PARAM; +drop type if exists tj.reactions_order_param; diff --git a/script/script/table/drop/2.junctions.sql b/script/script/table/drop/2.junctions.sql index ef0a609..0b436c4 100644 --- a/script/script/table/drop/2.junctions.sql +++ b/script/script/table/drop/2.junctions.sql @@ -1,3 +1,3 @@ --- [JUNCTIONS] +-- [junctions] -DROP TABLE IF EXISTS JUNCTIONS; +drop table if exists tj.junctions; diff --git a/script/script/table/drop/20.mixing.sql b/script/script/table/drop/20.mixing.sql index 938d554..f2adc25 100644 --- a/script/script/table/drop/20.mixing.sql +++ b/script/script/table/drop/20.mixing.sql @@ -1,5 +1,5 @@ --- [MIXING] +-- [mixing] -DROP TABLE IF EXISTS MIXING; +drop table if exists tj.mixing; -DROP TYPE IF EXISTS MIXING_Model; +drop type if exists tj.mixing_model; diff --git a/script/script/table/drop/21.times.sql b/script/script/table/drop/21.times.sql index f051bd7..b56a5cf 100644 --- a/script/script/table/drop/21.times.sql +++ b/script/script/table/drop/21.times.sql @@ -1,3 +1,3 @@ --- [TIMES] +-- [times] -DROP TABLE IF EXISTS TIMES; +drop table if exists tj.times; diff --git a/script/script/table/drop/22.report.sql b/script/script/table/drop/22.report.sql index 790684d..03f771b 100644 --- a/script/script/table/drop/22.report.sql +++ b/script/script/table/drop/22.report.sql @@ -1,3 +1,3 @@ --- [REPORT] +-- [report] -DROP TABLE IF EXISTS REPORT; +drop table if exists tj.report; diff --git a/script/script/table/drop/23.options.sql b/script/script/table/drop/23.options.sql index 7cc629a..dc8c63c 100644 --- a/script/script/table/drop/23.options.sql +++ b/script/script/table/drop/23.options.sql @@ -1,3 +1,3 @@ --- [OPTIONS] +-- [options] -DROP TABLE IF EXISTS OPTIONS; +drop table if exists tj.options; diff --git a/script/script/table/drop/24.coordinates.sql b/script/script/table/drop/24.coordinates.sql index 04d0465..e5d50b4 100644 --- a/script/script/table/drop/24.coordinates.sql +++ b/script/script/table/drop/24.coordinates.sql @@ -1,7 +1,7 @@ --- [COORDINATES] +-- [coordinates] -DROP INDEX IF EXISTS COORDINATES_GIST; +drop index if exists tj.coordinates_gist; -DROP INDEX IF EXISTS COORDINATES_SPGIST; +drop index if exists tj.coordinates_spgist; -DROP TABLE IF EXISTS COORDINATES; +drop table if exists tj.coordinates; diff --git a/script/script/table/drop/25.vertices.sql b/script/script/table/drop/25.vertices.sql index f74dd3e..a060c4a 100644 --- a/script/script/table/drop/25.vertices.sql +++ b/script/script/table/drop/25.vertices.sql @@ -1,3 +1,3 @@ --- [VERTICES] +-- [vertices] -DROP TABLE IF EXISTS VERTICES; +drop table if exists tj.vertices; diff --git a/script/script/table/drop/26.labels.sql b/script/script/table/drop/26.labels.sql index aa1b2b2..4f9f743 100644 --- a/script/script/table/drop/26.labels.sql +++ b/script/script/table/drop/26.labels.sql @@ -1,3 +1,3 @@ --- [LABELS] +-- [labels] -DROP TABLE IF EXISTS LABELS; +drop table if exists tj.labels; diff --git a/script/script/table/drop/27.backdrop.sql b/script/script/table/drop/27.backdrop.sql index 408bb85..ba47de7 100644 --- a/script/script/table/drop/27.backdrop.sql +++ b/script/script/table/drop/27.backdrop.sql @@ -1,3 +1,3 @@ --- [BACKDROP] +-- [backdrop] -DROP TABLE IF EXISTS BACKDROP; +drop table if exists tj.backdrop; diff --git a/script/script/table/drop/3.reservoirs.sql b/script/script/table/drop/3.reservoirs.sql index 9864c18..c9a1e25 100644 --- a/script/script/table/drop/3.reservoirs.sql +++ b/script/script/table/drop/3.reservoirs.sql @@ -1,3 +1,3 @@ --- [RESERVOIRS] +-- [reservoirs] -DROP TABLE IF EXISTS RESERVOIRS; +drop table if exists tj.reservoirs; diff --git a/script/script/table/drop/4.tanks.sql b/script/script/table/drop/4.tanks.sql index da0487d..0a5e589 100644 --- a/script/script/table/drop/4.tanks.sql +++ b/script/script/table/drop/4.tanks.sql @@ -1,5 +1,5 @@ --- [TANKS] +-- [tanks] -DROP TABLE IF EXISTS TANKS; +drop table if exists tj.tanks; -DROP TYPE IF EXISTS TANKS_OVERFLOW; +drop type if exists tj.tanks_overflow; diff --git a/script/script/table/drop/5.pipes.sql b/script/script/table/drop/5.pipes.sql index 1e23612..0cdc8dc 100644 --- a/script/script/table/drop/5.pipes.sql +++ b/script/script/table/drop/5.pipes.sql @@ -1,5 +1,5 @@ --- [PIPES] +-- [pipes] -DROP TABLE IF EXISTS PIPES; +drop table if exists tj.pipes; -DROP TYPE IF EXISTS PIPES_STATUS; +drop type if exists tj.pipes_status; diff --git a/script/script/table/drop/6.pumps.sql b/script/script/table/drop/6.pumps.sql index 5ac9656..18d697b 100644 --- a/script/script/table/drop/6.pumps.sql +++ b/script/script/table/drop/6.pumps.sql @@ -1,11 +1,11 @@ --- [PUMPS] +-- [pumps] -DROP TABLE IF EXISTS PUMPS_PROPERTY_PATTERN; +drop table if exists tj.pumps_property_pattern; -DROP TABLE IF EXISTS PUMPS_PROPERTY_HEAD; +drop table if exists tj.pumps_property_head; -DROP TABLE IF EXISTS PUMPS_PROPERTY_SPEED; +drop table if exists tj.pumps_property_speed; -DROP TABLE IF EXISTS PUMPS_PROPERTY_POWER; +drop table if exists tj.pumps_property_power; -DROP TABLE IF EXISTS PUMPS; +drop table if exists tj.pumps; diff --git a/script/script/table/drop/7.valves.sql b/script/script/table/drop/7.valves.sql index c95b423..0c2c2d1 100644 --- a/script/script/table/drop/7.valves.sql +++ b/script/script/table/drop/7.valves.sql @@ -1,5 +1,5 @@ --- [VALVES] +-- [valves] -DROP TABLE IF EXISTS VALVES; +drop table if exists tj.valves; -DROP TYPE IF EXISTS VALVES_TYPE; +drop type if exists tj.valves_type; diff --git a/script/script/table/drop/8.tags.sql b/script/script/table/drop/8.tags.sql index df8e3d1..e277759 100644 --- a/script/script/table/drop/8.tags.sql +++ b/script/script/table/drop/8.tags.sql @@ -1,5 +1,5 @@ --- [TAGS] +-- [tags] -DROP TABLE IF EXISTS TAGS_LINK; +drop table if exists tj.tags_link; -DROP TABLE IF EXISTS TAGS_NODE; +drop table if exists tj.tags_node; diff --git a/script/script/table/drop/9.demands.sql b/script/script/table/drop/9.demands.sql index ebe0209..8478a8b 100644 --- a/script/script/table/drop/9.demands.sql +++ b/script/script/table/drop/9.demands.sql @@ -1,3 +1,3 @@ --- [DEMANDS] +-- [demands] -DROP TABLE IF EXISTS DEMANDS; +drop table if exists tj.demands; diff --git a/script/script/table/drop/operation.sql b/script/script/table/drop/operation.sql index 998ee2f..cf3dc7b 100644 --- a/script/script/table/drop/operation.sql +++ b/script/script/table/drop/operation.sql @@ -1,7 +1,7 @@ -DROP TABLE IF EXISTS TRANSACTION_OPERATION; +drop table if exists tj.transaction_operation; -DROP TABLE IF EXISTS SNAPSHOT_OPERATION; +drop table if exists tj.snapshot_operation; -DROP TABLE IF EXISTS CURRENT_OPERATION; +drop table if exists tj.current_operation; -DROP TABLE IF EXISTS OPERATION; +drop table if exists tj.operation;