fix: make migrations 048/049 safe for environments without canonical tables
All checks were successful
CI/CD / go-lint (push) Has been skipped
CI/CD / python-lint (push) Has been skipped
CI/CD / nodejs-lint (push) Has been skipped
CI/CD / test-go-ai-compliance (push) Successful in 32s
CI/CD / test-python-backend-compliance (push) Successful in 33s
CI/CD / test-python-document-crawler (push) Successful in 21s
CI/CD / test-python-dsms-gateway (push) Successful in 17s
CI/CD / validate-canonical-controls (push) Successful in 12s
CI/CD / Deploy (push) Successful in 2s

Migrations 048 and 049 reference canonical_processed_chunks and
canonical_controls tables which may not exist on all environments.
Wrap ALTER TABLE statements in DO blocks that check for table
existence first. This unblocks migrations 050-053 on production.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-03-14 21:45:00 +01:00
parent c74f506415
commit 5f8aebf5b1
2 changed files with 29 additions and 19 deletions

View File

@@ -1,17 +1,22 @@
-- 048: Expand processing_path CHECK constraint for new pipeline paths
-- New values: prefilter_skip, no_control, store_failed, error
-- Safe: only runs if the table exists (may not exist on all environments)
ALTER TABLE canonical_processed_chunks
DROP CONSTRAINT IF EXISTS canonical_processed_chunks_processing_path_check;
ALTER TABLE canonical_processed_chunks
ADD CONSTRAINT canonical_processed_chunks_processing_path_check
CHECK (processing_path IN (
'structured', -- Rule 1/2: structured from original text
'llm_reform', -- Rule 3: LLM reformulated
'skipped', -- Legacy: skipped for other reasons
'prefilter_skip', -- Local LLM determined chunk has no requirement
'no_control', -- Processing ran but no control could be derived
'store_failed', -- Control generated but DB store failed
'error' -- Processing error occurred
));
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'canonical_processed_chunks') THEN
ALTER TABLE canonical_processed_chunks
DROP CONSTRAINT IF EXISTS canonical_processed_chunks_processing_path_check;
ALTER TABLE canonical_processed_chunks
ADD CONSTRAINT canonical_processed_chunks_processing_path_check
CHECK (processing_path IN (
'structured',
'llm_reform',
'skipped',
'prefilter_skip',
'no_control',
'store_failed',
'error'
));
END IF;
END $$;

View File

@@ -1,8 +1,13 @@
-- 049: Add target_audience field to canonical_controls
-- Distinguishes who a control is relevant for: enterprises, authorities, providers, or all.
-- Safe: only runs if the table exists (may not exist on all environments)
ALTER TABLE canonical_controls ADD COLUMN IF NOT EXISTS
target_audience VARCHAR(20) DEFAULT NULL
CHECK (target_audience IN ('enterprise', 'authority', 'provider', 'all'));
CREATE INDEX IF NOT EXISTS idx_cc_target_audience ON canonical_controls(target_audience);
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'canonical_controls') THEN
ALTER TABLE canonical_controls ADD COLUMN IF NOT EXISTS
target_audience VARCHAR(20) DEFAULT NULL
CHECK (target_audience IN ('enterprise', 'authority', 'provider', 'all'));
CREATE INDEX IF NOT EXISTS idx_cc_target_audience ON canonical_controls(target_audience);
END IF;
END $$;