"""Drop tasks_contact_id_fkey — contact_id is now derived from entity_id (ARCH-F-2). The tasks table has both a contact_id FK column (referencing contacts) and polymorphic entity_type/entity_id columns. The code now derives contact_id from entity_id when entity_type='contact', and stores NULL in the FK column. The FK constraint is redundant and prevents creating tasks with arbitrary entity references. This migration drops the FK constraint but keeps the column for backward compatibility. Revision ID: 0127 Revises: 0126 """ from alembic import op revision = "0127" down_revision = "0126" branch_labels = None depends_on = None def upgrade() -> None: # Drop the FK constraint on tasks.contact_id op.drop_constraint("tasks_contact_id_fkey", "tasks", type_="foreignkey") def downgrade() -> None: # Re-create the FK constraint (best-effort — may fail if orphaned rows exist) op.create_foreign_key( "tasks_contact_id_fkey", "tasks", "contacts", ["contact_id"], ["id"], ondelete="SET NULL", )