-- schema_pre_sync.sql -- Drops partial unique indexes created by schema_extras.sql before every -- sea-orm schema sync. The sync layer cannot express partial predicates via -- entity attributes, and treats these manually-created unique indexes as -- stale constraints (DROP CONSTRAINT), which fails because they are plain -- indexes. schema_extras.sql recreates all of them after the sync succeeds. DROP INDEX IF EXISTS idx_issue_watch_issue_user; DROP INDEX IF EXISTS idx_issue_watch_project_user; DROP INDEX IF EXISTS idx_issue_reaction_issue; DROP INDEX IF EXISTS idx_issue_reaction_comment; DROP INDEX IF EXISTS idx_issue_reaction_project; DROP INDEX IF EXISTS idx_branch_protection_whitelist_user; DROP INDEX IF EXISTS idx_branch_protection_whitelist_group; DROP INDEX IF EXISTS idx_chat_message_room_nonce; DROP INDEX IF EXISTS idx_chat_dm_pair; DROP INDEX IF EXISTS idx_chat_draft_unique; -- idempotent column adds for phase-2 model changes (sync layer cannot -- express NOT NULL DEFAULT additions on populated tables). -- Guarded with to_regclass: on a fresh database the tables do not exist yet -- (they are created by the registry sync right after, with these columns -- already included), so the ALTERs must be skipped instead of failing. DO $$ BEGIN IF to_regclass('room_members') IS NOT NULL THEN ALTER TABLE room_members ADD COLUMN IF NOT EXISTS role SMALLINT NOT NULL DEFAULT 0; END IF; END $$; DO $$ BEGIN IF to_regclass('issue') IS NOT NULL THEN ALTER TABLE issue ADD COLUMN IF NOT EXISTS priority SMALLINT NOT NULL DEFAULT 0; ALTER TABLE issue ADD COLUMN IF NOT EXISTS due_at TIMESTAMP WITH TIME ZONE; END IF; END $$; DO $$ BEGIN IF to_regclass('user_access_key') IS NOT NULL THEN ALTER TABLE user_access_key ADD COLUMN IF NOT EXISTS expires_at TIMESTAMP WITH TIME ZONE; ALTER TABLE user_access_key ADD COLUMN IF NOT EXISTS last_used_at TIMESTAMP WITH TIME ZONE; END IF; END $$; DO $$ BEGIN IF to_regclass('chat_message_reminder') IS NOT NULL THEN ALTER TABLE chat_message_reminder ADD COLUMN IF NOT EXISTS note TEXT; END IF; END $$;