From 94308e9e5cbbf04476244537a99920a4586c2df3 Mon Sep 17 00:00:00 2001 From: Ochenstarik Date: Tue, 29 Sep 2026 12:23:17 +0700 Subject: [PATCH] fix: harden sync database contracts --- .../0012_sync_contract_hardening.down.sql | 16 ++++++++++++++++ migrations/0012_sync_contract_hardening.up.sql | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 migrations/0012_sync_contract_hardening.down.sql create mode 100644 migrations/0012_sync_contract_hardening.up.sql diff --git a/migrations/0012_sync_contract_hardening.down.sql b/migrations/0012_sync_contract_hardening.down.sql new file mode 100644 index 0000000..37e4c21 --- /dev/null +++ b/migrations/0012_sync_contract_hardening.down.sql @@ -0,0 +1,16 @@ +ALTER TABLE staff_sync_command_inbox + DROP CONSTRAINT IF EXISTS staff_sync_command_inbox_correlation_id_check, + DROP CONSTRAINT IF EXISTS staff_sync_command_inbox_causation_id_check; + +ALTER TABLE staff_sync_command_inbox + ALTER COLUMN correlation_id TYPE VARCHAR(36), + ALTER COLUMN causation_id TYPE VARCHAR(36); + +ALTER TABLE staff_sync_devices + DROP CONSTRAINT IF EXISTS staff_sync_devices_tenant_id_org_unit_id_fkey; + +ALTER TABLE staff_sync_devices + ADD CONSTRAINT staff_sync_devices_tenant_id_org_unit_id_fkey + FOREIGN KEY (tenant_id, org_unit_id) + REFERENCES staff_org_units (tenant_id, id) + ON DELETE SET NULL; diff --git a/migrations/0012_sync_contract_hardening.up.sql b/migrations/0012_sync_contract_hardening.up.sql new file mode 100644 index 0000000..36abfaa --- /dev/null +++ b/migrations/0012_sync_contract_hardening.up.sql @@ -0,0 +1,18 @@ +ALTER TABLE staff_sync_devices + DROP CONSTRAINT IF EXISTS staff_sync_devices_tenant_id_org_unit_id_fkey; + +ALTER TABLE staff_sync_devices + ADD CONSTRAINT staff_sync_devices_tenant_id_org_unit_id_fkey + FOREIGN KEY (tenant_id, org_unit_id) + REFERENCES staff_org_units (tenant_id, id) + ON DELETE RESTRICT; + +ALTER TABLE staff_sync_command_inbox + ALTER COLUMN correlation_id TYPE VARCHAR(26), + ALTER COLUMN causation_id TYPE VARCHAR(26); + +ALTER TABLE staff_sync_command_inbox + ADD CONSTRAINT staff_sync_command_inbox_correlation_id_check + CHECK (correlation_id ~ '^[0-9A-HJKMNP-TV-Z]{26}$'), + ADD CONSTRAINT staff_sync_command_inbox_causation_id_check + CHECK (causation_id IS NULL OR causation_id ~ '^[0-9A-HJKMNP-TV-Z]{26}$');