diff --git a/backend/alembic/versions/021_fix_owner_id_nullable.py b/backend/alembic/versions/021_fix_owner_id_nullable.py new file mode 100644 index 00000000..28322bd2 --- /dev/null +++ b/backend/alembic/versions/021_fix_owner_id_nullable.py @@ -0,0 +1,30 @@ +"""fix accounts.owner_id to be nullable (circular FK with users) + +Revision ID: 021 +Revises: 020 +Create Date: 2026-02-07 + +The original migration 020 enforced NOT NULL on owner_id, but this creates +a circular FK problem: Account needs owner_id (User) and User needs +account_id (Account). Making owner_id nullable resolves this — we create +the Account first, then the User, then set owner_id. +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = '021' +down_revision: Union[str, None] = '020' +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + op.alter_column('accounts', 'owner_id', nullable=True) + + +def downgrade() -> None: + op.alter_column('accounts', 'owner_id', nullable=False)