fix: add migration 021 to make accounts.owner_id nullable on existing DBs
Railway already ran the old migration 020 which enforced NOT NULL on owner_id. Since alembic won't re-run a corrected 020, this new migration explicitly reverts the constraint for databases that already applied it. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
30
backend/alembic/versions/021_fix_owner_id_nullable.py
Normal file
30
backend/alembic/versions/021_fix_owner_id_nullable.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user