From cef631b41b151df63fa428f9d42a82c15630393d Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Fri, 24 Feb 2023 13:47:24 +0800 Subject: [PATCH] Refine scada tables --- script/sql/create/29.scada_device.sql | 9 +++++++++ script/sql/create/29.scada_model.sql | 15 --------------- ...30.scada_data.sql => 30.scada_device_data.sql} | 4 ++-- script/sql/create/31.scada_element.sql | 11 +++++++++++ script/sql/drop/29.scada_device.sql | 3 +++ script/sql/drop/29.scada_model.sql | 5 ----- script/sql/drop/30.scada_data.sql | 1 - script/sql/drop/30.scada_device_data.sql | 1 + script/sql/drop/31.scada_element.sql | 3 +++ script/template.py | 10 ++++++---- 10 files changed, 35 insertions(+), 27 deletions(-) create mode 100644 script/sql/create/29.scada_device.sql delete mode 100644 script/sql/create/29.scada_model.sql rename script/sql/create/{30.scada_data.sql => 30.scada_device_data.sql} (50%) create mode 100644 script/sql/create/31.scada_element.sql create mode 100644 script/sql/drop/29.scada_device.sql delete mode 100644 script/sql/drop/29.scada_model.sql delete mode 100644 script/sql/drop/30.scada_data.sql create mode 100644 script/sql/drop/30.scada_device_data.sql create mode 100644 script/sql/drop/31.scada_element.sql diff --git a/script/sql/create/29.scada_device.sql b/script/sql/create/29.scada_device.sql new file mode 100644 index 0000000..4f3cc3a --- /dev/null +++ b/script/sql/create/29.scada_device.sql @@ -0,0 +1,9 @@ +create type scada_device_type as enum ('PRESSURE', 'DEMAND', 'QUALITY', 'LEVEL', 'FLOW'); + +create table scada_device +( + id text primary key +, name text +, address text +, type scada_device_type +); diff --git a/script/sql/create/29.scada_model.sql b/script/sql/create/29.scada_model.sql deleted file mode 100644 index 1460b26..0000000 --- a/script/sql/create/29.scada_model.sql +++ /dev/null @@ -1,15 +0,0 @@ -create type scada_type as enum ('PRESSURE', 'DEMAND', 'QUALITY', 'LEVEL', 'FLOW'); -create type scada_status as enum ('OFF', 'ON'); - -create table scada_model -( - id text primary key -, x numeric not null -, y numeric not null -, device_id text not null unique -, device_name text -, address text -, type scada_type -, model_id varchar(32) -- add constraint in API -, status scada_status not null default 'OFF' -); diff --git a/script/sql/create/30.scada_data.sql b/script/sql/create/30.scada_device_data.sql similarity index 50% rename from script/sql/create/30.scada_data.sql rename to script/sql/create/30.scada_device_data.sql index 02c1643..8919bf6 100644 --- a/script/sql/create/30.scada_data.sql +++ b/script/sql/create/30.scada_device_data.sql @@ -1,6 +1,6 @@ -create table scada_data +create table scada_device_data ( - device_id text not null references scada_model(device_id) + device_id text not null references scada_device(id) , time timestamp not null , value numeric not null , primary key (device_id, time) diff --git a/script/sql/create/31.scada_element.sql b/script/sql/create/31.scada_element.sql new file mode 100644 index 0000000..6755f46 --- /dev/null +++ b/script/sql/create/31.scada_element.sql @@ -0,0 +1,11 @@ +create type scada_element_status as enum ('OFF', 'ON'); + +create table scada_element +( + id text primary key +, x numeric not null +, y numeric not null +, device_id text references scada_device(id) +, model_id varchar(32) -- add constraint in API +, status scada_element_status not null default 'OFF' +); diff --git a/script/sql/drop/29.scada_device.sql b/script/sql/drop/29.scada_device.sql new file mode 100644 index 0000000..d1ab139 --- /dev/null +++ b/script/sql/drop/29.scada_device.sql @@ -0,0 +1,3 @@ +drop table if exists scada_device; + +drop type if exists scada_device_type; diff --git a/script/sql/drop/29.scada_model.sql b/script/sql/drop/29.scada_model.sql deleted file mode 100644 index fe44555..0000000 --- a/script/sql/drop/29.scada_model.sql +++ /dev/null @@ -1,5 +0,0 @@ -drop table if exists scada_model; - -drop type if exists scada_status; - -drop type if exists scada_type; diff --git a/script/sql/drop/30.scada_data.sql b/script/sql/drop/30.scada_data.sql deleted file mode 100644 index daa81a0..0000000 --- a/script/sql/drop/30.scada_data.sql +++ /dev/null @@ -1 +0,0 @@ -drop table if exists scada_data; diff --git a/script/sql/drop/30.scada_device_data.sql b/script/sql/drop/30.scada_device_data.sql new file mode 100644 index 0000000..6771767 --- /dev/null +++ b/script/sql/drop/30.scada_device_data.sql @@ -0,0 +1 @@ +drop table if exists scada_device_data; diff --git a/script/sql/drop/31.scada_element.sql b/script/sql/drop/31.scada_element.sql new file mode 100644 index 0000000..5f467b8 --- /dev/null +++ b/script/sql/drop/31.scada_element.sql @@ -0,0 +1,3 @@ +drop table if exists scada_element; + +drop type if exists scada_element_status; diff --git a/script/template.py b/script/template.py index da61652..a15c882 100644 --- a/script/template.py +++ b/script/template.py @@ -30,15 +30,17 @@ sql_create = [ "sql/create/26.labels.sql", "sql/create/27.backdrop.sql", "sql/create/28.end.sql", - "sql/create/29.scada_model.sql", - "sql/create/30.scada_data.sql", + "sql/create/29.scada_device.sql", + "sql/create/30.scada_device_data.sql", + "sql/create/31.scada_element.sql", "sql/create/operation.sql" ] sql_drop = [ "sql/drop/operation.sql", - "sql/drop/30.scada_data.sql", - "sql/drop/29.scada_model.sql", + "sql/drop/31.scada_element.sql", + "sql/drop/30.scada_device_data.sql", + "sql/drop/29.scada_device.sql", "sql/drop/28.end.sql", "sql/drop/27.backdrop.sql", "sql/drop/26.labels.sql",