summaryrefslogblamecommitdiff
path: root/makima/migrations/20250110000008_remove_owner_defaults.sql
blob: 307f077c139640117a7c189a7520b03c9e7278a4 (plain) (tree)













































                                                                                                                                 
-- Remove default owner_id values from tables
-- This should be done after application code is updated to always provide owner_id

-- IMPORTANT: Only apply this migration after updating all code to provide owner_id
-- Otherwise, inserts will fail

-- Remove default values (they are no longer needed since code provides owner_id)
ALTER TABLE files
    ALTER COLUMN owner_id DROP DEFAULT;

ALTER TABLE tasks
    ALTER COLUMN owner_id DROP DEFAULT;

ALTER TABLE daemons
    ALTER COLUMN owner_id DROP DEFAULT;

ALTER TABLE mesh_chat_conversations
    ALTER COLUMN owner_id DROP DEFAULT;

-- Make owner_id NOT NULL explicit (should already be, but ensure)
-- Note: These columns were created with NOT NULL, so this is a no-op validation
-- The SET NOT NULL will succeed if all existing rows have non-null values

-- Files already has NOT NULL in original migration (20241222000000)
-- Tasks already has NOT NULL in original migration (20250102000000)
-- Daemons already has NOT NULL in original migration (20250102000000)
-- Mesh chat conversations already has NOT NULL in original migration (20250104000000)

-- However, we explicitly restate it for clarity and documentation
ALTER TABLE files
    ALTER COLUMN owner_id SET NOT NULL;

ALTER TABLE tasks
    ALTER COLUMN owner_id SET NOT NULL;

ALTER TABLE daemons
    ALTER COLUMN owner_id SET NOT NULL;

ALTER TABLE mesh_chat_conversations
    ALTER COLUMN owner_id SET NOT NULL;

-- Add comments documenting the constraint
COMMENT ON COLUMN files.owner_id IS 'Owner ID is required - no default value, must be provided by application';
COMMENT ON COLUMN tasks.owner_id IS 'Owner ID is required - no default value, must be provided by application';
COMMENT ON COLUMN daemons.owner_id IS 'Owner ID is required - no default value, must be provided by application';
COMMENT ON COLUMN mesh_chat_conversations.owner_id IS 'Owner ID is required - no default value, must be provided by application';