diff --git a/script/script/api/create/1.title.sql b/script/script/api/create/1.title.sql deleted file mode 100644 index fb81579..0000000 --- a/script/script/api/create/1.title.sql +++ /dev/null @@ -1,27 +0,0 @@ --- get_title() -create function tj.get_title() returns text as -$$ -declare - title text; -begin - select value into title from tj.title; - return title; -end; -$$ language plpgsql; - --- set_title() -create function tj.set_title(new_title text) returns void as -$$ -declare - old_title text; - redo text; - undo text; -begin - select tj.get_title() into old_title; - update tj.title set value = new_title where value = old_title; - - redo := concat('update tj.title set value = ''', new_title, ''' where value = ''', old_title, ''''); - undo := concat('update tj.title set value = ''', old_title, ''' where value = ''', new_title, ''''); - perform tj.add_operation(redo, undo); -end; -$$ language plpgsql; diff --git a/script/script/api/create/operation.sql b/script/script/api/create/operation.sql deleted file mode 100644 index ad56cdf..0000000 --- a/script/script/api/create/operation.sql +++ /dev/null @@ -1,109 +0,0 @@ -create function tj.add_operation(redo text, undo text) returns void as -$$ -declare - parent_id int; - curr_id int; -begin - select id into parent_id from tj.current_operation; - insert into tj.operation (id, redo, undo, parent) values (default, redo, undo, parent_id); - select max(id) into curr_id from tj.operation; - update tj.current_operation set id = curr_id where id = parent_id; -end; -$$ language plpgsql; - -create function tj.have_transaction() returns boolean as -$$ -declare - tran_count int; -begin - select count(*) into tran_count from tj.transaction_operation; - return tran_count > 0; -end; -$$ language plpgsql; - -create function tj.execute_undo(discard boolean) returns void as -$$ -declare - curr_id int; - have_tran boolean; - tran_id int; - strict_mode boolean; - undo_sql text; - parent_id int; -begin - select id into curr_id from tj.current_operation; - - select tj.have_transaction() into have_tran; - if have_tran then - select strict into strict_mode from tj.transaction_operation; - if strict_mode then - return; -- strict mode disallow undo - else - select id into tran_id from tj.transaction_operation; - if tran_id >= curr_id then - return; -- # normal mode disallow undo start point, and there is foreign key constraint - end if; - end if; - end if; - - select undo into undo_sql from tj.operation where id = curr_id; - if undo_sql = '' then - return; - end if; - - select parent into parent_id from tj.operation where id = curr_id; - if discard then - update tj.operation set redo_child = null where id = parent_id; - else - update tj.operation set redo_child = curr_id where id = parent_id; - end if; - - execute undo_sql; - - update tj.current_operation set id = parent_id where id = curr_id; - - if discard then - delete from tj.transaction_operation where id = curr_id; - delete from tj.snapshot_operation where id = curr_id; - delete from tj.operation where id = curr_id; - end if; -end; -$$ language plpgsql; - -create function tj.undo() returns void as -$$ -declare -begin - perform tj.execute_undo(false); -end; -$$ language plpgsql; - -create function tj.discard_undo() returns void as -$$ -declare -begin - perform tj.execute_undo(true); -end; -$$ language plpgsql; - -create function tj.redo() returns void as -$$ -declare - curr_id int; - child_id int; - redo_sql text; -begin - select id into curr_id from tj.current_operation; - - select redo_child into child_id from tj.operation where id = curr_id; - if child_id = null then - return; - end if; - - select redo into redo_sql from tj.operation where id = child_id; - - execute redo_sql; - - update tj.current_operation set id = child_id where id = curr_id; -end; -$$ language plpgsql; \ No newline at end of file diff --git a/script/script/api/create/project.sql b/script/script/api/create/project.sql deleted file mode 100644 index 50e8197..0000000 --- a/script/script/api/create/project.sql +++ /dev/null @@ -1,9 +0,0 @@ -create function tj.have_project(in_name text) returns boolean as -$$ -declare - db_count int; -begin - select count(*) into db_count from pg_database where datname = in_name; - return db_count > 0; -end; -$$ language plpgsql; diff --git a/script/script/api/drop/1.title.sql b/script/script/api/drop/1.title.sql deleted file mode 100644 index 9bef302..0000000 --- a/script/script/api/drop/1.title.sql +++ /dev/null @@ -1,3 +0,0 @@ -drop function if exists tj.set_title; - -drop function if exists tj.get_title; \ No newline at end of file diff --git a/script/script/api/drop/operation.sql b/script/script/api/drop/operation.sql deleted file mode 100644 index 1692da5..0000000 --- a/script/script/api/drop/operation.sql +++ /dev/null @@ -1,9 +0,0 @@ -drop function if exists tj.redo; - -drop function if exists tj.discard_undo; -drop function if exists tj.undo; -drop function if exists tj.execute_undo; - -drop function if exists tj.have_transaction; - -drop function if exists tj.add_operation; \ No newline at end of file diff --git a/script/script/api/plpgsql.sql b/script/script/api/plpgsql.sql deleted file mode 100644 index 06c96e0..0000000 --- a/script/script/api/plpgsql.sql +++ /dev/null @@ -1,6 +0,0 @@ -create function xxx() returns void as -$$ -declare -begin -end; -$$ language plpgsql; \ No newline at end of file diff --git a/script/script/table/create/0.base.sql b/script/script/table/create/0.base.sql deleted file mode 100644 index 91b48c0..0000000 --- a/script/script/table/create/0.base.sql +++ /dev/null @@ -1,35 +0,0 @@ -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 deleted file mode 100644 index 8ba6426..0000000 --- a/script/script/table/create/1.title.sql +++ /dev/null @@ -1,8 +0,0 @@ --- [title] - -create table tj.title -( - value text -); - -insert into tj.title (value) values (''); diff --git a/script/script/table/create/10.status.sql b/script/script/table/create/10.status.sql deleted file mode 100644 index c736c76..0000000 --- a/script/script/table/create/10.status.sql +++ /dev/null @@ -1,33 +0,0 @@ --- [status] - -create type tj.status_pipe_pump_status as enum -( - 'open' -, 'closed' -); - -create table tj.status_pipe -( - id varchar(32) primary key references tj.pipes(id) -, status tj.status_pipe_pump_status not null -); - -create table tj.status_pump -( - id varchar(32) primary key references tj.pumps(id) -, status tj.status_pipe_pump_status not null -); - -create type tj.status_valve_status as enum ('open', 'closed', 'active'); - -create table tj.status_valve -( - 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 deleted file mode 100644 index 8cd9ad6..0000000 --- a/script/script/table/create/11.patterns.sql +++ /dev/null @@ -1,7 +0,0 @@ --- [patterns] - -create table tj.patterns -( - 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 deleted file mode 100644 index 2467450..0000000 --- a/script/script/table/create/12.curves.sql +++ /dev/null @@ -1,8 +0,0 @@ --- [curves] - -create table tj.curves -( - 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 deleted file mode 100644 index ab34bb0..0000000 --- a/script/script/table/create/13.controls.sql +++ /dev/null @@ -1,30 +0,0 @@ --- [controls] - -create type tj.controls_1_prep as enum ('above', 'below'); - --- link linkid status if node nodeid above / below value -create table tj.controls_1 -( - 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 tj.controls_2 -( - 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 tj.controls_3 -( - 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 deleted file mode 100644 index 617da6b..0000000 --- a/script/script/table/create/14.rules.sql +++ /dev/null @@ -1,6 +0,0 @@ --- [rules] - -create table tj.rules -( - content text primary key -); diff --git a/script/script/table/create/15.energy.sql b/script/script/table/create/15.energy.sql deleted file mode 100644 index 1544968..0000000 --- a/script/script/table/create/15.energy.sql +++ /dev/null @@ -1,29 +0,0 @@ --- [energy] - -create type tj.energy_param as enum -( - 'price' -, 'pattern' -, 'effic' -); - --- global price / pattern / effic value -create table tj.energy_global -( - param tj.energy_param not null -, value numeric not null -); - --- pump pumpid price / pattern / effic value -create table tj.energy_pump -( - 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 deleted file mode 100644 index 448b9e1..0000000 --- a/script/script/table/create/16.emitters.sql +++ /dev/null @@ -1,7 +0,0 @@ --- [emitters] - -create table tj.emitters -( - 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 deleted file mode 100644 index e972b30..0000000 --- a/script/script/table/create/17.quality.sql +++ /dev/null @@ -1,7 +0,0 @@ --- [quality] - -create table tj.quality -( - 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 deleted file mode 100644 index 25d480d..0000000 --- a/script/script/table/create/18.sources.sql +++ /dev/null @@ -1,17 +0,0 @@ --- [sources] - -create type tj.sources_type as enum -( - '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 deleted file mode 100644 index 7ddab5d..0000000 --- a/script/script/table/create/19.reactions.sql +++ /dev/null @@ -1,55 +0,0 @@ --- [reactions] - -create type tj.reactions_order_param as enum -( - 'bulk' -, 'wall' -, 'tank' -); - -create table tj.reactions_order -( - key tj.reactions_order_param not null -, value numeric not null -); - -create type tj.reactions_global_param as enum -( - 'bulk' -, 'wall' -); - -create table tj.reactions_global -( - key tj.reactions_global_param not null -, value numeric not null -); - -create type tj.reactions_pipe_param as enum -( - 'bulk' -, 'wall' -); - -create table tj.reactions_pipe -( - 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 deleted file mode 100644 index 6397246..0000000 --- a/script/script/table/create/2.junctions.sql +++ /dev/null @@ -1,9 +0,0 @@ --- [junctions] - -create table tj.junctions -( - 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 deleted file mode 100644 index 65acf21..0000000 --- a/script/script/table/create/20.mixing.sql +++ /dev/null @@ -1,16 +0,0 @@ --- [mixing] - -create type tj.mixing_model as enum -( - '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 deleted file mode 100644 index f66ce2d..0000000 --- a/script/script/table/create/21.times.sql +++ /dev/null @@ -1,9 +0,0 @@ --- [times] - --- todo: constraint - -create table tj.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 deleted file mode 100644 index 4434a05..0000000 --- a/script/script/table/create/22.report.sql +++ /dev/null @@ -1,9 +0,0 @@ --- [report] - --- todo: constraint - -create table tj.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 deleted file mode 100644 index cab34f4..0000000 --- a/script/script/table/create/23.options.sql +++ /dev/null @@ -1,9 +0,0 @@ --- [options] - --- todo: constraint - -create table tj.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 deleted file mode 100644 index 9b2af3b..0000000 --- a/script/script/table/create/24.coordinates.sql +++ /dev/null @@ -1,10 +0,0 @@ --- [coordinates] - -create table tj.coordinates -( - node varchar(32) primary key references tj.node(id) -, coord point not null -); - -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 deleted file mode 100644 index 7b4d403..0000000 --- a/script/script/table/create/25.vertices.sql +++ /dev/null @@ -1,8 +0,0 @@ --- [vertices] - -create table tj.vertices -( - 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 deleted file mode 100644 index 3b41fce..0000000 --- a/script/script/table/create/26.labels.sql +++ /dev/null @@ -1,9 +0,0 @@ --- [labels] - -create table tj.labels -( - 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 deleted file mode 100644 index aea6d3b..0000000 --- a/script/script/table/create/27.backdrop.sql +++ /dev/null @@ -1,6 +0,0 @@ --- [backdrop] - -create table tj.backdrop -( - content text primary key -); diff --git a/script/script/table/create/28.end.sql b/script/script/table/create/28.end.sql deleted file mode 100644 index 3054ad0..0000000 --- a/script/script/table/create/28.end.sql +++ /dev/null @@ -1 +0,0 @@ --- [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 deleted file mode 100644 index e7562ec..0000000 --- a/script/script/table/create/3.reservoirs.sql +++ /dev/null @@ -1,8 +0,0 @@ --- [reservoirs] - -create table tj.reservoirs -( - 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 deleted file mode 100644 index 5a9a815..0000000 --- a/script/script/table/create/4.tanks.sql +++ /dev/null @@ -1,20 +0,0 @@ --- [tanks] - -create type tj.tanks_overflow as enum -( - '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 deleted file mode 100644 index d7ec73e..0000000 --- a/script/script/table/create/5.pipes.sql +++ /dev/null @@ -1,20 +0,0 @@ --- [pipes] - -create type tj.pipes_status as enum -( - '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 deleted file mode 100644 index 0f5b0cf..0000000 --- a/script/script/table/create/6.pumps.sql +++ /dev/null @@ -1,32 +0,0 @@ --- [pumps] - -create table tj.pumps -( - 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 tj.pumps_property_power -( - id varchar primary key references tj.pumps(id) -, value varchar(32) not null -); - -create table tj.pumps_property_speed -( - id varchar primary key references tj.pumps(id) -, value varchar(32) not null -); - -create table tj.pumps_property_head -( - id varchar primary key references tj.pumps(id) -, head varchar(32) references tj.curve(id) not null -); - -create table tj.pumps_property_pattern -( - 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 deleted file mode 100644 index 5aa584d..0000000 --- a/script/script/table/create/7.valves.sql +++ /dev/null @@ -1,22 +0,0 @@ --- [valves] - -create type tj.valves_type as enum -( - '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 deleted file mode 100644 index d98132c..0000000 --- a/script/script/table/create/8.tags.sql +++ /dev/null @@ -1,13 +0,0 @@ --- [tags] - -create table tj.tags_node -( - id varchar(32) primary key references tj.node(id) -, tag text not null -); - -create table tj.tags_link -( - 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 deleted file mode 100644 index e908227..0000000 --- a/script/script/table/create/9.demands.sql +++ /dev/null @@ -1,9 +0,0 @@ --- [demands] - -create table tj.demands -( - 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/namespace.sql b/script/script/table/create/namespace.sql deleted file mode 100644 index fc993ed..0000000 --- a/script/script/table/create/namespace.sql +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 524ef9e..0000000 --- a/script/script/table/create/operation.sql +++ /dev/null @@ -1,29 +0,0 @@ -create table tj.operation -( - 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 tj.operation (id, redo, undo) values (0, '', ''); - -create table tj.current_operation -( - id integer primary key references tj.operation(id) -); - -insert into tj.current_operation (id) values (0); - -create table tj.snapshot_operation -( - id integer primary key references tj.operation(id) -, tag text not null unique -); - -create table tj.transaction_operation -( - 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 deleted file mode 100644 index 41c4f41..0000000 --- a/script/script/table/drop/0.base.sql +++ /dev/null @@ -1,11 +0,0 @@ -drop table if exists tj.pattern; - -drop table if exists tj.curve; - -drop table if exists tj.link; - -drop table if exists tj.node; - -drop type if exists tj.link_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 deleted file mode 100644 index a03e80a..0000000 --- a/script/script/table/drop/1.title.sql +++ /dev/null @@ -1,3 +0,0 @@ --- [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 deleted file mode 100644 index 232ca4d..0000000 --- a/script/script/table/drop/10.status.sql +++ /dev/null @@ -1,13 +0,0 @@ --- [status] - -drop table if exists tj.status_link; - -drop table if exists tj.status_valve; - -drop type if exists tj.status_valve_status; - -drop table if exists tj.status_pump; - -drop table if exists tj.status_pipe; - -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 deleted file mode 100644 index 5fb2b47..0000000 --- a/script/script/table/drop/11.patterns.sql +++ /dev/null @@ -1,3 +0,0 @@ --- [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 deleted file mode 100644 index 4874ee8..0000000 --- a/script/script/table/drop/12.curves.sql +++ /dev/null @@ -1,3 +0,0 @@ --- [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 deleted file mode 100644 index f6c0502..0000000 --- a/script/script/table/drop/13.controls.sql +++ /dev/null @@ -1,9 +0,0 @@ --- [controls] - -drop table if exists tj.controls_3; - -drop table if exists tj.controls_2; - -drop table if exists tj.controls_1; - -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 deleted file mode 100644 index a920e6a..0000000 --- a/script/script/table/drop/14.rules.sql +++ /dev/null @@ -1,3 +0,0 @@ --- [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 deleted file mode 100644 index abf2e4a..0000000 --- a/script/script/table/drop/15.energy.sql +++ /dev/null @@ -1,9 +0,0 @@ --- [energy] - -drop table if exists tj.energy_demand_charge; - -drop table if exists tj.energy_pump; - -drop table if exists tj.energy_global; - -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 deleted file mode 100644 index ec23cd3..0000000 --- a/script/script/table/drop/16.emitters.sql +++ /dev/null @@ -1,3 +0,0 @@ --- [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 deleted file mode 100644 index 673cd2f..0000000 --- a/script/script/table/drop/17.quality.sql +++ /dev/null @@ -1,3 +0,0 @@ --- [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 deleted file mode 100644 index e9487c8..0000000 --- a/script/script/table/drop/18.sources.sql +++ /dev/null @@ -1,5 +0,0 @@ --- [sources] - -drop table if exists tj.sources; - -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 deleted file mode 100644 index 0dff3f0..0000000 --- a/script/script/table/drop/19.reactions.sql +++ /dev/null @@ -1,19 +0,0 @@ --- [reactions] - -drop table if exists tj.reactions_roughness_correlation; - -drop table if exists tj.reactions_limiting_potential; - -drop table if exists tj.reactions_tank; - -drop table if exists tj.reactions_pipe; - -drop type if exists tj.reactions_pipe_param; - -drop table if exists tj.reactions_global; - -drop type if exists tj.reactions_global_param; - -drop table if exists tj.reactions_order; - -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 deleted file mode 100644 index 0b436c4..0000000 --- a/script/script/table/drop/2.junctions.sql +++ /dev/null @@ -1,3 +0,0 @@ --- [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 deleted file mode 100644 index f2adc25..0000000 --- a/script/script/table/drop/20.mixing.sql +++ /dev/null @@ -1,5 +0,0 @@ --- [mixing] - -drop table if exists tj.mixing; - -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 deleted file mode 100644 index b56a5cf..0000000 --- a/script/script/table/drop/21.times.sql +++ /dev/null @@ -1,3 +0,0 @@ --- [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 deleted file mode 100644 index 03f771b..0000000 --- a/script/script/table/drop/22.report.sql +++ /dev/null @@ -1,3 +0,0 @@ --- [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 deleted file mode 100644 index dc8c63c..0000000 --- a/script/script/table/drop/23.options.sql +++ /dev/null @@ -1,3 +0,0 @@ --- [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 deleted file mode 100644 index 0d74d3e..0000000 --- a/script/script/table/drop/24.coordinates.sql +++ /dev/null @@ -1,7 +0,0 @@ --- [coordinates] - -drop index if exists tj_coordinates_gist; - -drop index if exists tj_coordinates_spgist; - -drop table if exists tj.coordinates; diff --git a/script/script/table/drop/25.vertices.sql b/script/script/table/drop/25.vertices.sql deleted file mode 100644 index a060c4a..0000000 --- a/script/script/table/drop/25.vertices.sql +++ /dev/null @@ -1,3 +0,0 @@ --- [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 deleted file mode 100644 index 4f9f743..0000000 --- a/script/script/table/drop/26.labels.sql +++ /dev/null @@ -1,3 +0,0 @@ --- [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 deleted file mode 100644 index ba47de7..0000000 --- a/script/script/table/drop/27.backdrop.sql +++ /dev/null @@ -1,3 +0,0 @@ --- [backdrop] - -drop table if exists tj.backdrop; diff --git a/script/script/table/drop/28.end.sql b/script/script/table/drop/28.end.sql deleted file mode 100644 index 3054ad0..0000000 --- a/script/script/table/drop/28.end.sql +++ /dev/null @@ -1 +0,0 @@ --- [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 deleted file mode 100644 index c9a1e25..0000000 --- a/script/script/table/drop/3.reservoirs.sql +++ /dev/null @@ -1,3 +0,0 @@ --- [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 deleted file mode 100644 index 0a5e589..0000000 --- a/script/script/table/drop/4.tanks.sql +++ /dev/null @@ -1,5 +0,0 @@ --- [tanks] - -drop table if exists tj.tanks; - -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 deleted file mode 100644 index 0cdc8dc..0000000 --- a/script/script/table/drop/5.pipes.sql +++ /dev/null @@ -1,5 +0,0 @@ --- [pipes] - -drop table if exists tj.pipes; - -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 deleted file mode 100644 index 18d697b..0000000 --- a/script/script/table/drop/6.pumps.sql +++ /dev/null @@ -1,11 +0,0 @@ --- [pumps] - -drop table if exists tj.pumps_property_pattern; - -drop table if exists tj.pumps_property_head; - -drop table if exists tj.pumps_property_speed; - -drop table if exists tj.pumps_property_power; - -drop table if exists tj.pumps; diff --git a/script/script/table/drop/7.valves.sql b/script/script/table/drop/7.valves.sql deleted file mode 100644 index 0c2c2d1..0000000 --- a/script/script/table/drop/7.valves.sql +++ /dev/null @@ -1,5 +0,0 @@ --- [valves] - -drop table if exists tj.valves; - -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 deleted file mode 100644 index e277759..0000000 --- a/script/script/table/drop/8.tags.sql +++ /dev/null @@ -1,5 +0,0 @@ --- [tags] - -drop table if exists tj.tags_link; - -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 deleted file mode 100644 index 8478a8b..0000000 --- a/script/script/table/drop/9.demands.sql +++ /dev/null @@ -1,3 +0,0 @@ --- [demands] - -drop table if exists tj.demands; diff --git a/script/script/table/drop/namespace.sql b/script/script/table/drop/namespace.sql deleted file mode 100644 index effb087..0000000 --- a/script/script/table/drop/namespace.sql +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index cf3dc7b..0000000 --- a/script/script/table/drop/operation.sql +++ /dev/null @@ -1,7 +0,0 @@ -drop table if exists tj.transaction_operation; - -drop table if exists tj.snapshot_operation; - -drop table if exists tj.current_operation; - -drop table if exists tj.operation; diff --git a/script/script/template.py b/script/script/template.py deleted file mode 100644 index 7ed9a98..0000000 --- a/script/script/template.py +++ /dev/null @@ -1,108 +0,0 @@ -import psycopg as pg - -sql_create = [ - "table/create/namespace.sql", - "table/create/0.base.sql", - "table/create/1.title.sql", - "table/create/2.junctions.sql", - "table/create/3.reservoirs.sql", - "table/create/4.tanks.sql", - "table/create/5.pipes.sql", - "table/create/6.pumps.sql", - "table/create/7.valves.sql", - "table/create/8.tags.sql", - "table/create/9.demands.sql", - "table/create/10.status.sql", - "table/create/11.patterns.sql", - "table/create/12.curves.sql", - "table/create/13.controls.sql", - "table/create/14.rules.sql", - "table/create/15.energy.sql", - "table/create/16.emitters.sql", - "table/create/17.quality.sql", - "table/create/18.sources.sql", - "table/create/19.reactions.sql", - "table/create/20.mixing.sql", - "table/create/21.times.sql", - "table/create/22.report.sql", - "table/create/23.options.sql", - "table/create/24.coordinates.sql", - "table/create/25.vertices.sql", - "table/create/26.labels.sql", - "table/create/27.backdrop.sql", - "table/create/28.end.sql", - "table/create/operation.sql", - "api/create/operation.sql", - "api/create/1.title.sql" -] - -sql_drop = [ - "api/drop/1.title.sql", - "api/drop/operation.sql", - "table/drop/operation.sql", - "table/drop/28.end.sql", - "table/drop/27.backdrop.sql", - "table/drop/26.labels.sql", - "table/drop/25.vertices.sql", - "table/drop/24.coordinates.sql", - "table/drop/23.options.sql", - "table/drop/22.report.sql", - "table/drop/21.times.sql", - "table/drop/20.mixing.sql", - "table/drop/19.reactions.sql", - "table/drop/18.sources.sql", - "table/drop/17.quality.sql", - "table/drop/16.emitters.sql", - "table/drop/15.energy.sql", - "table/drop/14.rules.sql", - "table/drop/13.controls.sql", - "table/drop/12.curves.sql", - "table/drop/11.patterns.sql", - "table/drop/10.status.sql", - "table/drop/9.demands.sql", - "table/drop/8.tags.sql", - "table/drop/7.valves.sql", - "table/drop/6.pumps.sql", - "table/drop/5.pipes.sql", - "table/drop/4.tanks.sql", - "table/drop/3.reservoirs.sql", - "table/drop/2.junctions.sql", - "table/drop/1.title.sql", - "table/drop/0.base.sql", - "table/drop/namespace.sql" -] - -def create_template(): - with pg.connect(conninfo="dbname=postgres", autocommit=True) as conn: - with conn.cursor() as cur: - cur.execute("create database tj_project") - with pg.connect(conninfo="dbname=tj_project") as conn: - with conn.cursor() as cur: - for sql in sql_create: - with open(sql, "r") as f: - cur.execute(f.read()) - print(f'executed {sql}') - conn.commit() - -def have_template(): - with pg.connect(conninfo="dbname=postgres", autocommit=True) as conn: - with conn.cursor() as cur: - cur.execute("select * from pg_database where datname = 'tj_project'") - return cur.rowcount > 0 - -def delete_template(): - with pg.connect(conninfo="dbname=tj_project") as conn: - with conn.cursor() as cur: - for sql in sql_drop: - with open(sql, "r") as f: - cur.execute(f.read()) - print(f'executed {sql}') - conn.commit() - with pg.connect(conninfo="dbname=postgres", autocommit=True) as conn: - with conn.cursor() as cur: - cur.execute("drop database tj_project") - -if __name__ == "__main__": - if (have_template()): - delete_template() - create_template()