正确处理ON DELETE CASCADE
This commit is contained in:
@@ -50,30 +50,13 @@ class EConfigure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function remove_server() {
|
function remove_server() {
|
||||||
pg_query($this -> dbconn, "BEGIN");
|
|
||||||
$exists = pg_query($this -> dbconn, sprintf(
|
|
||||||
"SELECT EXISTS(
|
|
||||||
SELECT 1 FROM hf_mes_scada_edgeserver_controller_device
|
|
||||||
WHERE server_id = '%s'
|
|
||||||
)", $this -> post -> id
|
|
||||||
));
|
|
||||||
if (pg_fetch_assoc($exists)['exists'] === 't') {
|
|
||||||
pg_query($this -> dbconn, "ROLLBACK");
|
|
||||||
return "REMAINING";
|
|
||||||
} else {
|
|
||||||
$res = pg_delete(
|
$res = pg_delete(
|
||||||
$this -> dbconn,
|
$this -> dbconn,
|
||||||
'hf_mes_scada_edgeserver_controller_server',
|
'hf_mes_scada_edgeserver_controller_server',
|
||||||
(array) $this -> post,
|
(array) $this -> post,
|
||||||
);
|
);
|
||||||
if ($res) {
|
|
||||||
pg_query($this -> dbconn, "COMMIT");
|
return $res ? true : "REMAINING";
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
pg_query($this -> dbconn, "ROLLBACK");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_server() {
|
function update_server() {
|
||||||
|
|||||||
@@ -12,8 +12,20 @@ function init_db($server_name, $port, $user, $password) {
|
|||||||
pg_query($dbconn, "CREATE EXTENSION IF NOT EXISTS timescaledb");
|
pg_query($dbconn, "CREATE EXTENSION IF NOT EXISTS timescaledb");
|
||||||
pg_query(
|
pg_query(
|
||||||
$dbconn,
|
$dbconn,
|
||||||
"CREATE TYPE category
|
"DO $$ BEGIN
|
||||||
AS ENUM ('DEVICE_STATUS', 'ITEM_ID', 'DEVICE_DATA', 'PROCESS_DATA', 'RESULT_DATA', 'STATISTICAL_DATA')"
|
CREATE TYPE category
|
||||||
|
AS ENUM (
|
||||||
|
'DEVICE_STATUS',
|
||||||
|
'ITEM_ID',
|
||||||
|
'DEVICE_DATA',
|
||||||
|
'PROCESS_DATA',
|
||||||
|
'RESULT_DATA',
|
||||||
|
'STATISTICAL_DATA'
|
||||||
|
);
|
||||||
|
EXCEPTION
|
||||||
|
WHEN duplicate_object
|
||||||
|
THEN null;
|
||||||
|
END $$"
|
||||||
);
|
);
|
||||||
pg_query($dbconn, "CREATE TABLE IF NOT EXISTS hf_mes_scada_data_capture_node_configure (
|
pg_query($dbconn, "CREATE TABLE IF NOT EXISTS hf_mes_scada_data_capture_node_configure (
|
||||||
id serial2 primary key,
|
id serial2 primary key,
|
||||||
@@ -42,14 +54,17 @@ function init_db($server_name, $port, $user, $password) {
|
|||||||
id serial2 primary key,
|
id serial2 primary key,
|
||||||
code text,
|
code text,
|
||||||
name text NOT NULL,
|
name text NOT NULL,
|
||||||
server_id serial2 references hf_mes_scada_edgeserver_controller_server(id),
|
server_id serial2
|
||||||
|
REFERENCES hf_mes_scada_edgeserver_controller_server(id),
|
||||||
conf json,
|
conf json,
|
||||||
create_date timestamp NOT NULL DEFAULT NOW(),
|
create_date timestamp NOT NULL DEFAULT NOW(),
|
||||||
note text
|
note text
|
||||||
)");
|
)");
|
||||||
pg_query($dbconn, "CREATE TABLE IF NOT EXISTS hf_mes_scada_edgeserver_controller_command (
|
pg_query($dbconn, "CREATE TABLE IF NOT EXISTS hf_mes_scada_edgeserver_controller_command (
|
||||||
id serial8 primary key,
|
id serial8 primary key,
|
||||||
server_id serial2 references hf_mes_scada_edgeserver_controller_server(id),
|
server_id serial2
|
||||||
|
REFERENCES hf_mes_scada_edgeserver_controller_server(id)
|
||||||
|
ON DELETE CASCADE,
|
||||||
device_name text,
|
device_name text,
|
||||||
command text,
|
command text,
|
||||||
create_date timestamp NOT NULL DEFAULT NOW(),
|
create_date timestamp NOT NULL DEFAULT NOW(),
|
||||||
|
|||||||
Reference in New Issue
Block a user