wulf-pulse/migrations/009_relax_configuration_items_constraints.sql

19 lines
683 B
MySQL
Raw Permalink Normal View History

-- Relax foreign key constraints for configuration_items sync
-- This allows configuration items to be synced even when referenced contacts don't exist
-- Make contact_id constraint deferrable and nullable
ALTER TABLE configuration_items
DROP CONSTRAINT IF EXISTS configuration_items_contact_id_fkey;
-- Add back the constraint as deferrable with ON DELETE SET NULL
ALTER TABLE configuration_items
ADD CONSTRAINT configuration_items_contact_id_fkey
FOREIGN KEY (contact_id)
REFERENCES contacts(id)
ON DELETE SET NULL
DEFERRABLE INITIALLY DEFERRED;
-- Ensure contact_id column is nullable
ALTER TABLE configuration_items
ALTER COLUMN contact_id DROP NOT NULL;