47 lines
2.9 KiB
PL/PgSQL
47 lines
2.9 KiB
PL/PgSQL
BEGIN;
|
|
DO $$ BEGIN
|
|
IF current_database() NOT IN ('tjwater_v2', 'tjwater2_v2') THEN
|
|
RAISE EXCEPTION '031_scada_replays requires an explicitly verified SCADA demo project';
|
|
END IF;
|
|
END $$;
|
|
|
|
CREATE TABLE IF NOT EXISTS peripheral_sample.scada_replays (
|
|
project_id uuid NOT NULL,
|
|
replay_id uuid NOT NULL,
|
|
request_id uuid NOT NULL,
|
|
status text NOT NULL CHECK (status IN ('ready','paused','completed','stopped','failed')),
|
|
document jsonb NOT NULL,
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
PRIMARY KEY (project_id,replay_id),
|
|
UNIQUE (project_id,request_id)
|
|
);
|
|
CREATE INDEX IF NOT EXISTS scada_replays_status_idx
|
|
ON peripheral_sample.scada_replays(project_id,status,created_at DESC);
|
|
CREATE TABLE IF NOT EXISTS peripheral_sample.scada_replay_batches (
|
|
project_id uuid NOT NULL,
|
|
replay_id uuid NOT NULL,
|
|
sequence bigint NOT NULL,
|
|
stage text NOT NULL CHECK(stage IN ('selected','clean_prepared','cleaned','detected')),
|
|
document jsonb NOT NULL,
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
PRIMARY KEY(project_id,replay_id,sequence),
|
|
FOREIGN KEY(project_id,replay_id) REFERENCES peripheral_sample.scada_replays(project_id,replay_id)
|
|
);
|
|
COMMENT ON TABLE peripheral_sample.scada_replays IS 'SCADA 演示回放的权威控制状态与处理检查点,不保存正式原始观测';
|
|
COMMENT ON COLUMN peripheral_sample.scada_replays.project_id IS '经认证与路由校验的所属项目';
|
|
COMMENT ON COLUMN peripheral_sample.scada_replays.replay_id IS '独立回放身份,不等同 Agent 执行编号';
|
|
COMMENT ON COLUMN peripheral_sample.scada_replays.request_id IS '创建请求的稳定幂等编号';
|
|
COMMENT ON COLUMN peripheral_sample.scada_replays.status IS '供领取和约束使用的 document.status 查询投影';
|
|
COMMENT ON COLUMN peripheral_sample.scada_replays.document IS '冻结配置、设备快照、时钟、检查点、规则状态和命令回执';
|
|
COMMENT ON COLUMN peripheral_sample.scada_replays.created_at IS '实际创建时间';
|
|
COMMENT ON COLUMN peripheral_sample.scada_replays.updated_at IS '实际控制或进度更新时间';
|
|
COMMENT ON TABLE peripheral_sample.scada_replay_batches IS 'SCADA raw 引用、清洗输出及检测阶段的恢复凭证,禁止重写 raw';
|
|
COMMENT ON COLUMN peripheral_sample.scada_replay_batches.project_id IS '所属项目';
|
|
COMMENT ON COLUMN peripheral_sample.scada_replay_batches.replay_id IS '所属回放';
|
|
COMMENT ON COLUMN peripheral_sample.scada_replay_batches.sequence IS '回放内单调批次序号';
|
|
COMMENT ON COLUMN peripheral_sample.scada_replay_batches.stage IS '已提交处理阶段';
|
|
COMMENT ON COLUMN peripheral_sample.scada_replay_batches.document IS '观测键、raw 摘要、确定的清洗结果与检测事件';
|
|
COMMENT ON COLUMN peripheral_sample.scada_replay_batches.created_at IS '实际登记批次时间';
|
|
COMMIT;
|