feat(scada): add project monitoring replay
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
BEGIN;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF to_regclass('public.project_databases') IS NULL
|
||||
OR to_regclass('public.user_project_membership') IS NULL THEN
|
||||
RAISE EXCEPTION '033_metadata_project_settings must run in the project metadata database';
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
ALTER TABLE public.projects
|
||||
ADD COLUMN IF NOT EXISTS settings jsonb NOT NULL DEFAULT '{}'::jsonb;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_constraint
|
||||
WHERE conrelid = 'public.projects'::regclass
|
||||
AND conname = 'projects_settings_object_check'
|
||||
) THEN
|
||||
ALTER TABLE public.projects
|
||||
ADD CONSTRAINT projects_settings_object_check
|
||||
CHECK (jsonb_typeof(settings) = 'object');
|
||||
END IF;
|
||||
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public' AND table_name = 'projects'
|
||||
AND column_name = 'scada_monitoring_interval_seconds'
|
||||
) THEN
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM public.projects
|
||||
WHERE scada_monitoring_interval_seconds IS NOT NULL
|
||||
AND settings ? 'scada_monitoring_interval_seconds'
|
||||
AND settings->'scada_monitoring_interval_seconds'
|
||||
IS DISTINCT FROM to_jsonb(scada_monitoring_interval_seconds)
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Conflicting SCADA monitoring intervals; resolve before migration';
|
||||
END IF;
|
||||
|
||||
UPDATE public.projects
|
||||
SET settings = settings || jsonb_build_object(
|
||||
'scada_monitoring_interval_seconds', scada_monitoring_interval_seconds
|
||||
)
|
||||
WHERE scada_monitoring_interval_seconds IS NOT NULL;
|
||||
|
||||
ALTER TABLE public.projects DROP COLUMN scada_monitoring_interval_seconds;
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
COMMENT ON COLUMN public.projects.settings IS
|
||||
'项目级通用配置(JSON 对象,不存放密钥);scada_monitoring_interval_seconds 为监测任务间隔秒数。';
|
||||
|
||||
COMMIT;
|
||||
Reference in New Issue
Block a user