From 9b97e47615a68d9795a996210a07ef7cf751b7c4 Mon Sep 17 00:00:00 2001 From: Sacha Al Himdani Date: Mon, 16 Feb 2026 16:04:52 +0100 Subject: [PATCH] Create safer approver migration Signed-off-by: Sacha Al Himdani --- pkg/coredata/migrations/20260212T120000Z.sql | 5 ----- pkg/coredata/migrations/20260213T120000Z.sql | 13 ++++++++++--- 2 files changed, 10 insertions(+), 8 deletions(-) delete mode 100644 pkg/coredata/migrations/20260212T120000Z.sql diff --git a/pkg/coredata/migrations/20260212T120000Z.sql b/pkg/coredata/migrations/20260212T120000Z.sql deleted file mode 100644 index fabcadde2..000000000 --- a/pkg/coredata/migrations/20260212T120000Z.sql +++ /dev/null @@ -1,5 +0,0 @@ --- Rename owner_profile_id to approver_profile_id on documents table -ALTER TABLE documents RENAME COLUMN owner_profile_id TO approver_profile_id; - --- Rename owner_profile_id to approver_profile_id on document_versions table -ALTER TABLE document_versions RENAME COLUMN owner_profile_id TO approver_profile_id; diff --git a/pkg/coredata/migrations/20260213T120000Z.sql b/pkg/coredata/migrations/20260213T120000Z.sql index 4837564d1..f06726696 100644 --- a/pkg/coredata/migrations/20260213T120000Z.sql +++ b/pkg/coredata/migrations/20260213T120000Z.sql @@ -1,3 +1,9 @@ +-- Rename owner_profile_id to approver_profile_id on documents table +ALTER TABLE documents RENAME COLUMN owner_profile_id TO approver_profile_id; + +-- Rename owner_profile_id to approver_profile_id on document_versions table +ALTER TABLE document_versions RENAME COLUMN owner_profile_id TO approver_profile_id; + -- Create document_approvers join table CREATE TABLE document_approvers ( document_id TEXT NOT NULL REFERENCES documents(id) ON DELETE CASCADE, @@ -31,6 +37,7 @@ SELECT id, approver_profile_id, tenant_id, organization_id, created_at FROM document_versions WHERE approver_profile_id IS NOT NULL; --- Drop the old columns -ALTER TABLE documents DROP COLUMN approver_profile_id; -ALTER TABLE document_versions DROP COLUMN approver_profile_id; +-- Allow NULL on old columns now that data is in the join tables +ALTER TABLE document_versions ALTER COLUMN approver_profile_id DROP NOT NULL; + +-- TODO: Drop the old columns