删除发版无关的文件
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
-- ============================================
|
||||
-- TJWater Server 用户系统数据库迁移脚本
|
||||
-- ============================================
|
||||
|
||||
-- 创建用户表
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
username VARCHAR(50) UNIQUE NOT NULL,
|
||||
email VARCHAR(100) UNIQUE NOT NULL,
|
||||
hashed_password VARCHAR(255) NOT NULL,
|
||||
role VARCHAR(20) DEFAULT 'USER' NOT NULL,
|
||||
is_active BOOLEAN DEFAULT TRUE NOT NULL,
|
||||
is_superuser BOOLEAN DEFAULT FALSE NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
|
||||
CONSTRAINT users_role_check CHECK (role IN ('ADMIN', 'OPERATOR', 'USER', 'VIEWER'))
|
||||
);
|
||||
|
||||
-- 创建索引
|
||||
CREATE INDEX IF NOT EXISTS idx_users_username ON users(username);
|
||||
CREATE INDEX IF NOT EXISTS idx_users_email ON users(email);
|
||||
CREATE INDEX IF NOT EXISTS idx_users_role ON users(role);
|
||||
CREATE INDEX IF NOT EXISTS idx_users_is_active ON users(is_active);
|
||||
|
||||
-- 创建触发器自动更新 updated_at
|
||||
CREATE OR REPLACE FUNCTION update_updated_at_column()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
NEW.updated_at = CURRENT_TIMESTAMP;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
DROP TRIGGER IF EXISTS update_users_updated_at ON users;
|
||||
CREATE TRIGGER update_users_updated_at
|
||||
BEFORE UPDATE ON users
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION update_updated_at_column();
|
||||
|
||||
-- 创建默认管理员账号 (密码: admin123)
|
||||
INSERT INTO users (username, email, hashed_password, role, is_superuser)
|
||||
VALUES (
|
||||
'admin',
|
||||
'admin@tjwater.com',
|
||||
'$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5aeAJK.1tYKAW',
|
||||
'ADMIN',
|
||||
TRUE
|
||||
) ON CONFLICT (username) DO NOTHING;
|
||||
|
||||
-- 迁移现有硬编码用户 (tjwater/tjwater@123)
|
||||
INSERT INTO users (username, email, hashed_password, role, is_superuser)
|
||||
VALUES (
|
||||
'tjwater',
|
||||
'tjwater@tjwater.com',
|
||||
'$2b$12$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW',
|
||||
'ADMIN',
|
||||
TRUE
|
||||
) ON CONFLICT (username) DO NOTHING;
|
||||
|
||||
-- 添加注释
|
||||
COMMENT ON TABLE users IS '用户表 - 存储系统用户信息';
|
||||
COMMENT ON COLUMN users.id IS '用户ID(主键)';
|
||||
COMMENT ON COLUMN users.username IS '用户名(唯一)';
|
||||
COMMENT ON COLUMN users.email IS '邮箱地址(唯一)';
|
||||
COMMENT ON COLUMN users.hashed_password IS 'bcrypt 密码哈希';
|
||||
COMMENT ON COLUMN users.role IS '用户角色: ADMIN, OPERATOR, USER, VIEWER';
|
||||
@@ -1,45 +0,0 @@
|
||||
-- ============================================
|
||||
-- TJWater Server 审计日志表迁移脚本
|
||||
-- ============================================
|
||||
|
||||
-- 创建审计日志表
|
||||
CREATE TABLE IF NOT EXISTS audit_logs (
|
||||
id SERIAL PRIMARY KEY,
|
||||
user_id INTEGER REFERENCES users(id) ON DELETE SET NULL,
|
||||
username VARCHAR(50),
|
||||
action VARCHAR(50) NOT NULL,
|
||||
resource_type VARCHAR(50),
|
||||
resource_id VARCHAR(100),
|
||||
ip_address VARCHAR(45),
|
||||
user_agent TEXT,
|
||||
request_method VARCHAR(10),
|
||||
request_path TEXT,
|
||||
request_data JSONB,
|
||||
response_status INTEGER,
|
||||
error_message TEXT,
|
||||
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
|
||||
);
|
||||
|
||||
-- 创建索引以提高查询性能
|
||||
CREATE INDEX IF NOT EXISTS idx_audit_logs_user_id ON audit_logs(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_audit_logs_username ON audit_logs(username);
|
||||
CREATE INDEX IF NOT EXISTS idx_audit_logs_timestamp ON audit_logs(timestamp DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_audit_logs_action ON audit_logs(action);
|
||||
CREATE INDEX IF NOT EXISTS idx_audit_logs_resource ON audit_logs(resource_type, resource_id);
|
||||
|
||||
-- 添加注释
|
||||
COMMENT ON TABLE audit_logs IS '审计日志表 - 记录所有关键操作';
|
||||
COMMENT ON COLUMN audit_logs.id IS '日志ID(主键)';
|
||||
COMMENT ON COLUMN audit_logs.user_id IS '用户ID(外键)';
|
||||
COMMENT ON COLUMN audit_logs.username IS '用户名(冗余字段,用于用户删除后仍可查询)';
|
||||
COMMENT ON COLUMN audit_logs.action IS '操作类型(如:LOGIN, LOGOUT, CREATE, UPDATE, DELETE)';
|
||||
COMMENT ON COLUMN audit_logs.resource_type IS '资源类型(如:user, project, network)';
|
||||
COMMENT ON COLUMN audit_logs.resource_id IS '资源ID';
|
||||
COMMENT ON COLUMN audit_logs.ip_address IS '客户端IP地址';
|
||||
COMMENT ON COLUMN audit_logs.user_agent IS '客户端User-Agent';
|
||||
COMMENT ON COLUMN audit_logs.request_method IS 'HTTP请求方法';
|
||||
COMMENT ON COLUMN audit_logs.request_path IS '请求路径';
|
||||
COMMENT ON COLUMN audit_logs.request_data IS '请求数据(JSON格式,敏感信息已脱敏)';
|
||||
COMMENT ON COLUMN audit_logs.response_status IS 'HTTP响应状态码';
|
||||
COMMENT ON COLUMN audit_logs.error_message IS '错误消息(如果有)';
|
||||
COMMENT ON COLUMN audit_logs.timestamp IS '操作时间';
|
||||
@@ -1,36 +0,0 @@
|
||||
create type _node_type as enum ('junction', 'reservoir', 'tank');
|
||||
|
||||
create type _link_type as enum ('pipe', 'pump', 'valve');
|
||||
|
||||
create type _curve_type as enum ('PUMP', 'EFFICIENCY', 'VOLUME', 'HEADLOSS');
|
||||
|
||||
create type _region_type as enum ('NONE', 'DMA', 'SA', 'VD', 'WDA');
|
||||
|
||||
create table _node
|
||||
(
|
||||
id varchar(32) primary key
|
||||
, type _node_type not null
|
||||
);
|
||||
|
||||
create table _link
|
||||
(
|
||||
id varchar(32) primary key
|
||||
, type _link_type not null
|
||||
);
|
||||
|
||||
create table _curve
|
||||
(
|
||||
id varchar(32) primary key
|
||||
, type _curve_type not null
|
||||
);
|
||||
|
||||
create table _pattern
|
||||
(
|
||||
id varchar(32) primary key
|
||||
);
|
||||
|
||||
create table _region
|
||||
(
|
||||
id varchar(32) primary key
|
||||
, type _region_type not null
|
||||
);
|
||||
@@ -1,8 +0,0 @@
|
||||
-- [TITLE]
|
||||
|
||||
create table title
|
||||
(
|
||||
value text
|
||||
);
|
||||
|
||||
insert into title (value) values ('');
|
||||
@@ -1,13 +0,0 @@
|
||||
-- [STATUS]
|
||||
|
||||
create type link_status as enum ('OPEN', 'CLOSED', 'ACTIVE');
|
||||
|
||||
create table status
|
||||
(
|
||||
link varchar(32) primary key references _link(id)
|
||||
, status link_status
|
||||
, setting float8
|
||||
, check (status is not null or setting is not null)
|
||||
);
|
||||
|
||||
-- ddelete when delete link
|
||||
@@ -1,8 +0,0 @@
|
||||
-- [PATTERNS]
|
||||
|
||||
create table patterns
|
||||
(
|
||||
_order serial primary key
|
||||
, id varchar(32) references _pattern(id) not null
|
||||
, factor float8 not null
|
||||
);
|
||||
@@ -1,9 +0,0 @@
|
||||
-- [CURVES]
|
||||
|
||||
create table curves
|
||||
(
|
||||
_order serial primary key
|
||||
, id varchar(32) references _curve(id) not null
|
||||
, x float8 not null
|
||||
, y float8 not null
|
||||
);
|
||||
@@ -1,7 +0,0 @@
|
||||
-- [CONTROLS]
|
||||
|
||||
create table controls
|
||||
(
|
||||
_order serial primary key
|
||||
, line text not null
|
||||
);
|
||||
@@ -1,7 +0,0 @@
|
||||
-- [RULES]
|
||||
|
||||
create table rules
|
||||
(
|
||||
_order serial primary key
|
||||
, line text not null
|
||||
);
|
||||
@@ -1,40 +0,0 @@
|
||||
-- [ENERGY]
|
||||
|
||||
create table energy
|
||||
(
|
||||
key text primary key
|
||||
, value text not null
|
||||
);
|
||||
|
||||
insert into energy (key, value) values
|
||||
('GLOBAL PRICE', '0')
|
||||
, ('GLOBAL PATTERN', '')
|
||||
, ('GLOBAL EFFIC', '75')
|
||||
, ('DEMAND CHARGE', '0')
|
||||
;
|
||||
|
||||
create table energy_pump_price
|
||||
(
|
||||
pump varchar(32) primary key references pumps(id) not null
|
||||
, price float8 not null
|
||||
);
|
||||
|
||||
-- delete when delete pump
|
||||
|
||||
create table energy_pump_pattern
|
||||
(
|
||||
pump varchar(32) primary key references pumps(id) not null
|
||||
, pattern varchar(32) references _pattern(id) not null
|
||||
);
|
||||
|
||||
-- delete when delete pump
|
||||
-- delete when delete pattern
|
||||
|
||||
create table energy_pump_effic
|
||||
(
|
||||
pump varchar(32) primary key references pumps(id) not null
|
||||
, effic varchar(32) references _curve(id) not null
|
||||
);
|
||||
|
||||
-- delete when delete pump
|
||||
-- delete when delete curve
|
||||
@@ -1,9 +0,0 @@
|
||||
-- [EMITTERS]
|
||||
|
||||
create table emitters
|
||||
(
|
||||
junction varchar(32) primary key references junctions(id)
|
||||
, coefficient float8 not null
|
||||
);
|
||||
|
||||
-- delete when delete junction
|
||||
@@ -1,9 +0,0 @@
|
||||
-- [QUALITY]
|
||||
|
||||
create table quality
|
||||
(
|
||||
node varchar(32) primary key references _node(id)
|
||||
, quality float8 not null
|
||||
);
|
||||
|
||||
-- delete when delete ndoe
|
||||
@@ -1,14 +0,0 @@
|
||||
-- [SOURCES]
|
||||
|
||||
create type sources_type as enum ('CONCEN', 'MASS', 'FLOWPACED', 'SETPOINT');
|
||||
|
||||
create table sources
|
||||
(
|
||||
node varchar(32) primary key references _node(id)
|
||||
, s_type sources_type not null
|
||||
, strength float8 not null
|
||||
, pattern varchar(32) references _pattern(id)
|
||||
);
|
||||
|
||||
-- delete when delete node
|
||||
-- unset pattern when delete pattern
|
||||
@@ -1,41 +0,0 @@
|
||||
-- [REACTIONS]
|
||||
|
||||
create table reactions
|
||||
(
|
||||
key text primary key
|
||||
, value text not null
|
||||
);
|
||||
|
||||
insert into reactions (key, value) values
|
||||
('ORDER BULK', '1')
|
||||
, ('ORDER WALL', '1')
|
||||
, ('ORDER TANK', '1')
|
||||
, ('GLOBAL BULK', '0')
|
||||
, ('GLOBAL WALL', '0')
|
||||
, ('LIMITING POTENTIAL', '0')
|
||||
, ('ROUGHNESS CORRELATION', '0')
|
||||
;
|
||||
|
||||
create table reactions_pipe_bulk
|
||||
(
|
||||
pipe varchar(32) primary key references pipes(id) not null
|
||||
, value float8 not null
|
||||
);
|
||||
|
||||
-- delete when delete pipe
|
||||
|
||||
create table reactions_pipe_wall
|
||||
(
|
||||
pipe varchar(32) primary key references pipes(id) not null
|
||||
, value float8 not null
|
||||
);
|
||||
|
||||
-- delete when delete pipe
|
||||
|
||||
create table reactions_tank
|
||||
(
|
||||
tank varchar(32) primary key references tanks(id) not null
|
||||
, value float8 not null
|
||||
);
|
||||
|
||||
-- delete when delete tank
|
||||
@@ -1,7 +0,0 @@
|
||||
-- [JUNCTIONS]
|
||||
|
||||
create table junctions
|
||||
(
|
||||
id varchar(32) primary key references _node(id)
|
||||
, elevation float8 not null
|
||||
);
|
||||
@@ -1,12 +0,0 @@
|
||||
-- [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 float8
|
||||
);
|
||||
|
||||
-- delete when delete tank
|
||||
@@ -1,20 +0,0 @@
|
||||
-- [TIMES]
|
||||
|
||||
create table times
|
||||
(
|
||||
key text primary key
|
||||
, value text not null
|
||||
);
|
||||
|
||||
insert into times (key, value) values
|
||||
('DURATION', '0:00')
|
||||
, ('HYDRAULIC TIMESTEP', '1:00')
|
||||
, ('QUALITY TIMESTEP', '0:05')
|
||||
, ('RULE TIMESTEP', '0:05')
|
||||
, ('PATTERN TIMESTEP', '1:00')
|
||||
, ('PATTERN START', '0:00')
|
||||
, ('REPORT TIMESTEP', '1:00')
|
||||
, ('REPORT START', '0:00')
|
||||
, ('START CLOCKTIME', '12:00 AM')
|
||||
, ('STATISTIC', 'NONE') -- NONE / AVERAGED / MINIMUM / MAXIMUM / RANGE
|
||||
;
|
||||
@@ -1,18 +0,0 @@
|
||||
-- [REPORT]
|
||||
|
||||
create table report
|
||||
(
|
||||
key text primary key
|
||||
, value text not null
|
||||
);
|
||||
|
||||
insert into report (key, value) values
|
||||
('PAGESIZE', '0')
|
||||
--, ('FILE', '')
|
||||
, ('STATUS', 'FULL')
|
||||
, ('SUMMARY', 'YES')
|
||||
, ('MESSAGES', 'YES')
|
||||
, ('ENERGY', 'YES')
|
||||
, ('NODES', 'ALL')
|
||||
, ('LINKS', 'ALL')
|
||||
;
|
||||
@@ -1,77 +0,0 @@
|
||||
-- [OPTIONS]
|
||||
|
||||
-- TODO: constraint
|
||||
|
||||
create table options
|
||||
(
|
||||
key text primary key
|
||||
, value text not null
|
||||
);
|
||||
|
||||
insert into options (key, value) values
|
||||
('UNITS', 'LPS')
|
||||
, ('PRESSURE', 'METERS')
|
||||
, ('HEADLOSS', 'H-W')
|
||||
, ('QUALITY', 'NONE')
|
||||
, ('UNBALANCED', 'STOP')
|
||||
, ('PATTERN', '1')
|
||||
, ('DEMAND MODEL', 'DDA')
|
||||
, ('DEMAND MULTIPLIER', '1.0')
|
||||
, ('EMITTER EXPONENT', '0.5')
|
||||
, ('VISCOSITY', '1.0')
|
||||
, ('DIFFUSIVITY', '1.0')
|
||||
, ('SPECIFIC GRAVITY', '1.0')
|
||||
, ('TRIALS', '40')
|
||||
, ('ACCURACY', '0.001')
|
||||
, ('HEADERROR', '0.0001')
|
||||
, ('FLOWCHANGE', '0.0001')
|
||||
, ('MINIMUM PRESSURE', '0.0001')
|
||||
, ('REQUIRED PRESSURE', '20.0')
|
||||
, ('PRESSURE EXPONENT', '0.5')
|
||||
, ('TOLERANCE', '0.01')
|
||||
, ('HTOL', '0.0005')
|
||||
, ('QTOL', '0.0001')
|
||||
, ('RQTOL', '0.0000001')
|
||||
, ('CHECKFREQ', '2')
|
||||
, ('MAXCHECK', '10')
|
||||
, ('DAMPLIMIT', '0')
|
||||
;
|
||||
|
||||
|
||||
create table options_v3
|
||||
(
|
||||
key text primary key
|
||||
, value text not null
|
||||
);
|
||||
|
||||
insert into options_v3 (key, value) values
|
||||
('FLOW_UNITS', 'LPS')
|
||||
, ('PRESSURE_UNITS', 'METERS')
|
||||
, ('HEADLOSS_MODEL', 'H-W')
|
||||
, ('SPECIFIC_GRAVITY', '1.0')
|
||||
, ('SPECIFIC_VISCOSITY', '1.0')
|
||||
, ('MAXIMUM_TRIALS', '40')
|
||||
, ('HEAD_TOLERANCE', '0.0005')
|
||||
, ('FLOW_TOLERANCE', '0.0001')
|
||||
, ('FLOW_CHANGE_LIMIT', '0.0001')
|
||||
, ('RELATIVE_ACCURACY', '0.001')
|
||||
, ('TIME_WEIGHT', '0.0')
|
||||
, ('STEP_SIZING', 'FULL')
|
||||
, ('IF_UNBALANCED', 'STOP')
|
||||
, ('DEMAND_MODEL', 'FIXED')
|
||||
, ('DEMAND_PATTERN', '1')
|
||||
, ('DEMAND_MULTIPLIER', '1.0')
|
||||
, ('MINIMUM_PRESSURE', '0.0001')
|
||||
, ('SERVICE_PRESSURE', '20.0')
|
||||
, ('PRESSURE_EXPONENT', '0.5')
|
||||
, ('LEAKAGE_MODEL', 'NONE')
|
||||
, ('LEAKAGE_COEFF1', '0.0')
|
||||
, ('LEAKAGE_COEFF2', '0.0')
|
||||
, ('EMITTER_EXPONENT', '0.5')
|
||||
, ('QUALITY_MODEL', 'NONE')
|
||||
, ('QUALITY_NAME', 'CHEMICAL')
|
||||
, ('QUALITY_UNITS', 'MG/L')
|
||||
, ('TRACE_NODE', '')
|
||||
, ('SPECIFIC_DIFFUSIVITY', '1.0')
|
||||
, ('QUALITY_TOLERANCE', '0.01')
|
||||
;
|
||||
@@ -1,11 +0,0 @@
|
||||
-- [COORDINATES]
|
||||
|
||||
create table coordinates
|
||||
(
|
||||
node varchar(32) primary key references _node(id)
|
||||
, coord geometry
|
||||
);
|
||||
|
||||
-- delete when delete node
|
||||
|
||||
create index coordinates_gist on coordinates using gist(coord);
|
||||
@@ -1,11 +0,0 @@
|
||||
-- [VERTICES]
|
||||
|
||||
create table vertices
|
||||
(
|
||||
_order serial primary key
|
||||
, link varchar(32) references _link(id) not null
|
||||
, x float8 not null
|
||||
, y float8 not null
|
||||
);
|
||||
|
||||
-- delete when delete link
|
||||
@@ -1,12 +0,0 @@
|
||||
-- [LABELS]
|
||||
|
||||
create table labels
|
||||
(
|
||||
x float8 not null
|
||||
, y float8 not null
|
||||
, label text not null
|
||||
, node varchar(32) references _node(id)
|
||||
, primary key (x, y)
|
||||
);
|
||||
|
||||
-- unset node when delete node
|
||||
@@ -1,8 +0,0 @@
|
||||
-- [BACKDROP]
|
||||
|
||||
create table backdrop
|
||||
(
|
||||
content text primary key
|
||||
);
|
||||
|
||||
insert into backdrop (content) values ('');
|
||||
@@ -1 +0,0 @@
|
||||
-- [END]
|
||||
@@ -1,9 +0,0 @@
|
||||
create type scada_device_type as enum ('PRESSURE', 'DEMAND', 'QUALITY', 'LEVEL', 'FLOW', 'UNKNOWN');
|
||||
|
||||
create table scada_device
|
||||
(
|
||||
id text primary key
|
||||
, name text
|
||||
, address text
|
||||
, sd_type scada_device_type
|
||||
);
|
||||
@@ -1,10 +0,0 @@
|
||||
-- [RESERVOIRS]
|
||||
|
||||
create table reservoirs
|
||||
(
|
||||
id varchar(32) primary key references _node(id)
|
||||
, head float8 not null
|
||||
, pattern varchar(32) references _pattern(id)
|
||||
);
|
||||
|
||||
-- unset pattern when delete pattern
|
||||
@@ -1,7 +0,0 @@
|
||||
create table scada_device_data
|
||||
(
|
||||
device_id text not null references scada_device(id)
|
||||
, time timestamp not null
|
||||
, value float8 not null
|
||||
, primary key (device_id, time)
|
||||
);
|
||||
@@ -1,14 +0,0 @@
|
||||
create type scada_model_type as enum ('JUNCTION', 'RESERVOIR', 'TANK', 'PIPE', 'PUMP', 'VALVE');
|
||||
|
||||
create type scada_element_status as enum ('OFF', 'ON');
|
||||
|
||||
create table scada_element
|
||||
(
|
||||
id text primary key
|
||||
, x float8 not null
|
||||
, y float8 not null
|
||||
, device_id text references scada_device(id)
|
||||
, model_id varchar(32) -- add constraint in API
|
||||
, model_type scada_model_type
|
||||
, status scada_element_status not null default 'OFF'
|
||||
);
|
||||
@@ -1,48 +0,0 @@
|
||||
create type region_type as enum ('NONE', 'DMA', 'SA', 'VD', 'WDA');
|
||||
|
||||
create table region
|
||||
(
|
||||
id text primary key
|
||||
, boundary geometry not null --unique
|
||||
, r_type region_type not null default 'NONE'
|
||||
);
|
||||
|
||||
create index region_gist on region using gist(boundary);
|
||||
|
||||
|
||||
create table temp_region
|
||||
(
|
||||
id text primary key
|
||||
, boundary geometry not null unique
|
||||
);
|
||||
|
||||
create index temp_region_gist on temp_region using gist(boundary);
|
||||
|
||||
|
||||
create table temp_node
|
||||
(
|
||||
node varchar(32) primary key references _node(id)
|
||||
);
|
||||
|
||||
|
||||
create table temp_link_1
|
||||
(
|
||||
link varchar(32) primary key references _link(id)
|
||||
, geom geometry not null unique
|
||||
);
|
||||
|
||||
|
||||
create table temp_link_2
|
||||
(
|
||||
link varchar(32) primary key references _link(id)
|
||||
, geom geometry not null unique
|
||||
);
|
||||
|
||||
|
||||
create table temp_vd_topology
|
||||
(
|
||||
id serial
|
||||
, source integer
|
||||
, target integer
|
||||
, cost float8
|
||||
);
|
||||
@@ -1,6 +0,0 @@
|
||||
create table region_dma
|
||||
(
|
||||
id text primary key references region(id)
|
||||
, parent text --references region_dma(id)
|
||||
, nodes text not null
|
||||
);
|
||||
@@ -1,7 +0,0 @@
|
||||
create table region_sa
|
||||
(
|
||||
id text primary key references region(id)
|
||||
, time_index integer not null
|
||||
, source varchar(32) not null -- references _node(id)
|
||||
, nodes text not null
|
||||
);
|
||||
@@ -1,6 +0,0 @@
|
||||
create table region_vd
|
||||
(
|
||||
id text primary key references region(id)
|
||||
, center varchar(32) not null -- references _node(id)
|
||||
, nodes text not null
|
||||
);
|
||||
@@ -1,5 +0,0 @@
|
||||
create table region_wda
|
||||
(
|
||||
id text primary key references region(id)
|
||||
, demand float8 not null default 0.0
|
||||
);
|
||||
@@ -1,11 +0,0 @@
|
||||
-- [HISTORY_PATTERNS_FLOWS]
|
||||
-- WMH
|
||||
-- 2025/01/12
|
||||
-- Save pattern and pattern based history flow data. Use it for flow update pattern
|
||||
create table history_patterns_flows
|
||||
(
|
||||
_order serial primary key
|
||||
, id varchar(32) references _pattern(id) not null
|
||||
, factor float8 not null
|
||||
, flow float8 not null
|
||||
);
|
||||
@@ -1,44 +0,0 @@
|
||||
-- [SCADA_INFO]
|
||||
-- 王名豪
|
||||
-- 2025/01/12
|
||||
-- 存储水厂提供的SCADA设备相关数据,包括设备ID、类型(reservoir_liquid_level/tank_liquid_level/fixed_pump/variable_pump/source_outflow/pipe_flow/pressure/demand/quality、关联的模型元素ID、关联的模式、
|
||||
-- 关联的干管流量计对应的模型元素ID(即demand(大用户)处于某个pipe_flow(干管流量计)之下,demand不是根据水量大小来确定的,而是根据设备情况和是否单独设置pattern决定
|
||||
-- 关联的出厂流量计对应的模型元素ID若干个(即确认该设备的水源是哪几个,根据水源不同,设置为不同的分区)
|
||||
-- SCADA设备通过数据接口查询的ID、传输模式(实时/非实时)、传输频率(多久传回一次数据)
|
||||
-- X坐标、Y坐标、基于X坐标和Y坐标生成geometry类型的数据
|
||||
|
||||
create table scada_info
|
||||
(
|
||||
id varchar(32) primary key
|
||||
, type varchar(32) not null
|
||||
, associated_element_id varchar(32) not null
|
||||
, associated_pattern varchar(32)
|
||||
, associated_pipe_flow_id varchar(32)
|
||||
, associated_source_outflow_id1 varchar(32)
|
||||
, associated_source_outflow_id2 varchar(32)
|
||||
, associated_source_outflow_id3 varchar(32)
|
||||
, associated_source_outflow_id4 varchar(32)
|
||||
, associated_source_outflow_id5 varchar(32)
|
||||
, associated_source_outflow_id6 varchar(32)
|
||||
, associated_source_outflow_id7 varchar(32)
|
||||
, associated_source_outflow_id8 varchar(32)
|
||||
, associated_source_outflow_id9 varchar(32)
|
||||
, associated_source_outflow_id10 varchar(32)
|
||||
, associated_source_outflow_id11 varchar(32)
|
||||
, associated_source_outflow_id12 varchar(32)
|
||||
, associated_source_outflow_id13 varchar(32)
|
||||
, associated_source_outflow_id14 varchar(32)
|
||||
, associated_source_outflow_id15 varchar(32)
|
||||
, associated_source_outflow_id16 varchar(32)
|
||||
, associated_source_outflow_id17 varchar(32)
|
||||
, associated_source_outflow_id18 varchar(32)
|
||||
, associated_source_outflow_id19 varchar(32)
|
||||
, associated_source_outflow_id20 varchar(32)
|
||||
, API_query_id varchar(32)
|
||||
, transmission_mode varchar(32) not null
|
||||
, transmission_frequency text not null
|
||||
, reliability int not null
|
||||
, X_coor float8 not null
|
||||
, Y_coor float8 not null
|
||||
, coord geometry
|
||||
)
|
||||
@@ -1,10 +0,0 @@
|
||||
-- [USERS]
|
||||
-- 王名豪
|
||||
-- 2025/03/23
|
||||
-- 存储系统的用户信息,如用户名,密码
|
||||
|
||||
create table users (
|
||||
user_id SERIAL PRIMARY KEY,
|
||||
username varchar(32) not null unique,
|
||||
password varchar(32) not null
|
||||
)
|
||||
@@ -1,18 +0,0 @@
|
||||
-- [TANKS]
|
||||
|
||||
create type tanks_overflow as enum ('YES', 'NO');
|
||||
|
||||
create table tanks
|
||||
(
|
||||
id varchar(32) primary key references _node(id)
|
||||
, elevation float8 not null
|
||||
, init_level float8 not null
|
||||
, min_level float8 not null
|
||||
, max_level float8 not null
|
||||
, diameter float8 not null
|
||||
, min_vol float8 not null
|
||||
, vol_curve varchar(32) references _curve(id)
|
||||
, overflow tanks_overflow
|
||||
);
|
||||
|
||||
-- unset vol_curve when delete curve
|
||||
@@ -1,14 +0,0 @@
|
||||
-- [SCHEME_LIST]
|
||||
-- 王名豪
|
||||
-- 2025/03/23
|
||||
-- 存储进行手动模拟后的方案列表
|
||||
|
||||
create table scheme_list (
|
||||
scheme_id SERIAL PRIMARY KEY,
|
||||
scheme_name varchar(32) not null,
|
||||
scheme_type varchar(32) not null,
|
||||
username varchar(32) not null REFERENCES "users"(username) ON UPDATE CASCADE ON DELETE RESTRICT,
|
||||
create_time TIMESTAMP WITH TIME ZONE not null DEFAULT date_trunc('minute', CURRENT_TIMESTAMP),
|
||||
scheme_start_time varchar(50) not null,
|
||||
scheme_detail JSON
|
||||
)
|
||||
@@ -1,13 +0,0 @@
|
||||
-- [PIPE_RISK_PROBABILITY]
|
||||
-- 王名豪
|
||||
-- 2025/04/16
|
||||
-- 存储管道风险评价结果
|
||||
|
||||
CREATE TABLE pipe_risk_probability (
|
||||
id SERIAL PRIMARY KEY,
|
||||
pipeID VARCHAR(255),
|
||||
pipeage FLOAT,
|
||||
risk_probability_now FLOAT,
|
||||
x FLOAT[], -- Since x is a list, it's stored as text (stringified list)
|
||||
y FLOAT[] -- Similarly, y will be stored as text (stringified list)
|
||||
);
|
||||
@@ -1,14 +0,0 @@
|
||||
-- [SENSOR_PLACEMENT]
|
||||
-- 王名豪
|
||||
-- 2025/04/18
|
||||
-- 存储测压点的布置方案
|
||||
|
||||
CREATE TABLE sensor_placement (
|
||||
id SERIAL PRIMARY KEY,
|
||||
scheme_name varchar(32) not null,
|
||||
sensor_number int,
|
||||
min_diameter int,
|
||||
username varchar(32) not null REFERENCES "users"(username) ON UPDATE CASCADE ON DELETE RESTRICT,
|
||||
create_time TIMESTAMP WITH TIME ZONE not null DEFAULT date_trunc('minute', CURRENT_TIMESTAMP),
|
||||
sensor_location TEXT[]
|
||||
);
|
||||
@@ -1,13 +0,0 @@
|
||||
-- [BURST_LOCATE_RESULT]
|
||||
-- 王名豪
|
||||
-- 2025/04/19
|
||||
-- 存储爆管侦测定位结果
|
||||
|
||||
CREATE TABLE burst_locate_result (
|
||||
id SERIAL PRIMARY KEY,
|
||||
type varchar(32) not null,
|
||||
burst_incident varchar(32) not null,
|
||||
leakage float,
|
||||
detect_time TIMESTAMP WITH TIME ZONE not null DEFAULT date_trunc('minute', CURRENT_TIMESTAMP),
|
||||
locate_result JSON
|
||||
)
|
||||
@@ -1,19 +0,0 @@
|
||||
-- [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 float8 not null
|
||||
, diameter float8 not null
|
||||
, roughness float8 not null
|
||||
, minor_loss float8 not null
|
||||
, status pipes_status not null
|
||||
, check (node1 <> node2)
|
||||
);
|
||||
|
||||
-- delete when delete node1
|
||||
-- delete when delete node2
|
||||
@@ -1,19 +0,0 @@
|
||||
-- [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
|
||||
, power float8
|
||||
, head varchar(32) references _curve(id)
|
||||
, speed float8
|
||||
, pattern varchar(32) references _pattern(id)
|
||||
, check (power is not null or head is not null)
|
||||
, check ((power is not null and head is not null) is false)
|
||||
);
|
||||
|
||||
-- delete when delete node1
|
||||
-- delete when delete node2
|
||||
-- unset head when delete curve
|
||||
-- unset pattern when delete pattern
|
||||
@@ -1,17 +0,0 @@
|
||||
-- [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 float8 not null
|
||||
, v_type valves_type not null
|
||||
, setting text not null
|
||||
, minor_loss float8 not null
|
||||
);
|
||||
|
||||
-- delete when delete node1
|
||||
-- delete when delete node2
|
||||
@@ -1,17 +0,0 @@
|
||||
-- [TAGS]
|
||||
|
||||
create table tags_node
|
||||
(
|
||||
id varchar(32) primary key references _node(id)
|
||||
, tag text not null
|
||||
);
|
||||
|
||||
-- delete when delete node
|
||||
|
||||
create table tags_link
|
||||
(
|
||||
id varchar(32) primary key references _link(id)
|
||||
, tag text not null
|
||||
);
|
||||
|
||||
-- delete when delete link
|
||||
@@ -1,13 +0,0 @@
|
||||
-- [DEMANDS]
|
||||
|
||||
create table demands
|
||||
(
|
||||
_order serial primary key
|
||||
, junction varchar(32) references junctions(id) not null
|
||||
, demand float8 not null
|
||||
, pattern varchar(32) references _pattern(id)
|
||||
, category text
|
||||
);
|
||||
|
||||
-- delete when delete junction
|
||||
-- unset pattern when delete pattern
|
||||
@@ -1,5 +0,0 @@
|
||||
create table extension_data
|
||||
(
|
||||
key text primary key
|
||||
, value text not null
|
||||
);
|
||||
@@ -1,55 +0,0 @@
|
||||
create table operation
|
||||
(
|
||||
id bigserial primary key
|
||||
, redo text not null
|
||||
, undo text not null
|
||||
, parent integer references operation(id) on delete cascade
|
||||
, redo_child integer references operation(id) -- must update before delete
|
||||
, redo_cs text not null
|
||||
, undo_cs text not null
|
||||
);
|
||||
|
||||
insert into operation (id, redo, undo, redo_cs, undo_cs) values (0, '', '', '', '');
|
||||
|
||||
create table current_operation
|
||||
(
|
||||
id bigint primary key references operation(id) -- must update before delete
|
||||
);
|
||||
|
||||
insert into current_operation (id) values (0);
|
||||
|
||||
create table snapshot_operation
|
||||
(
|
||||
id bigint primary key references operation(id) on delete cascade
|
||||
, tag text not null unique
|
||||
);
|
||||
|
||||
create table restore_operation
|
||||
(
|
||||
id bigint primary key references operation(id) -- set after reading inp
|
||||
);
|
||||
|
||||
insert into restore_operation (id) values (0);
|
||||
|
||||
|
||||
create table batch_operation
|
||||
(
|
||||
id bigserial primary key
|
||||
, redo text not null
|
||||
, undo text not null
|
||||
, parent integer references operation(id) on delete cascade
|
||||
, redo_child integer references operation(id) -- must update before delete
|
||||
, redo_cs text not null
|
||||
, undo_cs text not null
|
||||
);
|
||||
|
||||
insert into batch_operation (id, redo, undo, redo_cs, undo_cs) values (0, '', '', '', '');
|
||||
|
||||
create type operation_table_option as enum ('operation', 'batch_operation');
|
||||
|
||||
create table operation_table
|
||||
(
|
||||
option operation_table_option primary key
|
||||
);
|
||||
|
||||
insert into operation_table (option) values ('operation');
|
||||
@@ -1,15 +0,0 @@
|
||||
drop table if exists _region;
|
||||
|
||||
drop table if exists _pattern;
|
||||
|
||||
drop table if exists _curve;
|
||||
|
||||
drop table if exists _link;
|
||||
|
||||
drop table if exists _node;
|
||||
|
||||
drop type if exists _curve_type;
|
||||
|
||||
drop type if exists _link_type;
|
||||
|
||||
drop type if exists _node_type;
|
||||
@@ -1,3 +0,0 @@
|
||||
-- [TITLE]
|
||||
|
||||
drop table if exists title;
|
||||
@@ -1,5 +0,0 @@
|
||||
-- [STATUS]
|
||||
|
||||
drop table if exists status;
|
||||
|
||||
drop type if exists link_status;
|
||||
@@ -1,3 +0,0 @@
|
||||
-- [PATTERNS]
|
||||
|
||||
drop table if exists patterns;
|
||||
@@ -1,3 +0,0 @@
|
||||
-- [CURVES]
|
||||
|
||||
drop table if exists curves;
|
||||
@@ -1,3 +0,0 @@
|
||||
-- [CONTROLS]
|
||||
|
||||
drop table if exists controls;
|
||||
@@ -1,3 +0,0 @@
|
||||
-- [RULES]
|
||||
|
||||
drop table if exists rules;
|
||||
@@ -1,9 +0,0 @@
|
||||
-- [ENERGY]
|
||||
|
||||
drop table if exists energy_pump_effic;
|
||||
|
||||
drop table if exists energy_pump_pattern;
|
||||
|
||||
drop table if exists energy_pump_price;
|
||||
|
||||
drop table if exists energy;
|
||||
@@ -1,3 +0,0 @@
|
||||
-- [EMITTERS]
|
||||
|
||||
drop table if exists emitters;
|
||||
@@ -1,3 +0,0 @@
|
||||
-- [QUALITY]
|
||||
|
||||
drop table if exists quality;
|
||||
@@ -1,5 +0,0 @@
|
||||
-- [SOURCES]
|
||||
|
||||
drop table if exists sources;
|
||||
|
||||
drop type if exists sources_type;
|
||||
@@ -1,9 +0,0 @@
|
||||
-- [REACTIONS]
|
||||
|
||||
drop table if exists reactions_tank;
|
||||
|
||||
drop table if exists reactions_pipe_wall;
|
||||
|
||||
drop table if exists reactions_pipe_bulk;
|
||||
|
||||
drop table if exists reactions;
|
||||
@@ -1,3 +0,0 @@
|
||||
-- [JUNCTIONS]
|
||||
|
||||
drop table if exists junctions;
|
||||
@@ -1,5 +0,0 @@
|
||||
-- [MIXING]
|
||||
|
||||
drop table if exists mixing;
|
||||
|
||||
drop type if exists mixing_model;
|
||||
@@ -1,3 +0,0 @@
|
||||
-- [TIMES]
|
||||
|
||||
drop table if exists times;
|
||||
@@ -1,3 +0,0 @@
|
||||
-- [REPORT]
|
||||
|
||||
drop table if exists report;
|
||||
@@ -1,5 +0,0 @@
|
||||
-- [OPTIONS]
|
||||
|
||||
drop table if exists options_v3;
|
||||
|
||||
drop table if exists options;
|
||||
@@ -1,5 +0,0 @@
|
||||
-- [COORDINATES]
|
||||
|
||||
drop index if exists coordinates_gist;
|
||||
|
||||
drop table if exists coordinates;
|
||||
@@ -1,3 +0,0 @@
|
||||
-- [VERTICES]
|
||||
|
||||
drop table if exists vertices;
|
||||
@@ -1,3 +0,0 @@
|
||||
-- [LABELS]
|
||||
|
||||
drop table if exists labels;
|
||||
@@ -1,3 +0,0 @@
|
||||
-- [BACKDROP]
|
||||
|
||||
drop table if exists backdrop;
|
||||
@@ -1 +0,0 @@
|
||||
-- [END]
|
||||
@@ -1,3 +0,0 @@
|
||||
drop table if exists scada_device;
|
||||
|
||||
drop type if exists scada_device_type;
|
||||
@@ -1,3 +0,0 @@
|
||||
-- [RESERVOIRS]
|
||||
|
||||
drop table if exists reservoirs;
|
||||
@@ -1 +0,0 @@
|
||||
drop table if exists scada_device_data;
|
||||
@@ -1,5 +0,0 @@
|
||||
drop table if exists scada_element;
|
||||
|
||||
drop type if exists scada_element_status;
|
||||
|
||||
drop type if exists scada_model_type;
|
||||
@@ -1,17 +0,0 @@
|
||||
drop table if exists temp_vd_topology;
|
||||
|
||||
drop table if exists temp_link_2;
|
||||
|
||||
drop table if exists temp_link_1;
|
||||
|
||||
drop table if exists temp_node;
|
||||
|
||||
drop index if exists temp_region_gist;
|
||||
|
||||
drop table if exists temp_region;
|
||||
|
||||
drop index if exists region_gist;
|
||||
|
||||
drop table if exists region;
|
||||
|
||||
drop type if exists region_type;
|
||||
@@ -1 +0,0 @@
|
||||
drop table if exists region_dma;
|
||||
@@ -1 +0,0 @@
|
||||
drop table if exists region_sa;
|
||||
@@ -1 +0,0 @@
|
||||
drop table if exists region_vd;
|
||||
@@ -1 +0,0 @@
|
||||
drop table if exists region_wda;
|
||||
@@ -1,3 +0,0 @@
|
||||
-- WMH
|
||||
-- 2025/01/12
|
||||
drop table if exists history_patterns_flows;
|
||||
@@ -1,3 +0,0 @@
|
||||
-- WMH
|
||||
-- 2025/01/12
|
||||
drop table if exists scada_info;
|
||||
@@ -1,5 +0,0 @@
|
||||
-- 王名豪
|
||||
-- 2025/03/23
|
||||
-- 删除user这张表
|
||||
|
||||
drop table if exists users;
|
||||
@@ -1,5 +0,0 @@
|
||||
-- [TANKS]
|
||||
|
||||
drop table if exists tanks;
|
||||
|
||||
drop type if exists tanks_overflow;
|
||||
@@ -1,6 +0,0 @@
|
||||
-- [SCHEME_LIST]
|
||||
-- 王名豪
|
||||
-- 2025/03/23
|
||||
-- 删除scheme_list这张表
|
||||
|
||||
drop table if exists scheme_list;
|
||||
@@ -1,6 +0,0 @@
|
||||
-- [PIPE_RISK_PROBABILITY]
|
||||
-- 王名豪
|
||||
-- 2025/04/16
|
||||
-- 删除pipe_risk_probability这张表
|
||||
|
||||
drop table if exists pipe_risk_probability;
|
||||
@@ -1,6 +0,0 @@
|
||||
-- [SENSOR_PLACEMENT]
|
||||
-- 王名豪
|
||||
-- 2025/04/18
|
||||
-- 删除sensor_placement这张表
|
||||
|
||||
drop table if exists sensor_placement;
|
||||
@@ -1,6 +0,0 @@
|
||||
-- [BURST_LOCATE_RESULT]
|
||||
-- 王名豪
|
||||
-- 2025/04/19
|
||||
-- 删除burst_locate_result这张表
|
||||
|
||||
drop table if exists burst_locate_result;
|
||||
@@ -1,5 +0,0 @@
|
||||
-- [PIPES]
|
||||
|
||||
drop table if exists pipes;
|
||||
|
||||
drop type if exists pipes_status;
|
||||
@@ -1,3 +0,0 @@
|
||||
-- [PUMPS]
|
||||
|
||||
drop table if exists pumps;
|
||||
@@ -1,5 +0,0 @@
|
||||
-- [VALVES]
|
||||
|
||||
drop table if exists valves;
|
||||
|
||||
drop type if exists valves_type;
|
||||
@@ -1,5 +0,0 @@
|
||||
-- [TAGS]
|
||||
|
||||
drop table if exists tags_link;
|
||||
|
||||
drop table if exists tags_node;
|
||||
@@ -1,3 +0,0 @@
|
||||
-- [DEMANDS]
|
||||
|
||||
drop table if exists demands;
|
||||
@@ -1 +0,0 @@
|
||||
drop table if exists extension_data;
|
||||
@@ -1,13 +0,0 @@
|
||||
drop table if exists operation_table;
|
||||
|
||||
drop type if exists operation_table_option;
|
||||
|
||||
drop table if exists batch_operation;
|
||||
|
||||
drop table if exists restore_operation;
|
||||
|
||||
drop table if exists snapshot_operation;
|
||||
|
||||
drop table if exists current_operation;
|
||||
|
||||
drop table if exists operation;
|
||||
Reference in New Issue
Block a user