kanban-app/backend/migrations/versions/bf430156bcf2_add_card_links_table.py

50 lines
1.9 KiB
Python
Raw Permalink Normal View History

"""add_card_links_table
Revision ID: bf430156bcf2
Revises: a9709e7ed22d
Create Date: 2026-04-30 19:37:25.884514
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'bf430156bcf2'
down_revision = 'a9709e7ed22d'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('card_links',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('parent_card_id', sa.Integer(), nullable=False),
sa.Column('child_card_id', sa.Integer(), nullable=False),
sa.Column('created_by', sa.Integer(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['child_card_id'], ['cards.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['created_by'], ['users.id'], ),
sa.ForeignKeyConstraint(['parent_card_id'], ['cards.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('parent_card_id', 'child_card_id', name='unique_card_link')
)
with op.batch_alter_table('card_links', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_card_links_child_card_id'), ['child_card_id'], unique=False)
batch_op.create_index(batch_op.f('ix_card_links_created_by'), ['created_by'], unique=False)
batch_op.create_index(batch_op.f('ix_card_links_parent_card_id'), ['parent_card_id'], unique=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('card_links', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_card_links_parent_card_id'))
batch_op.drop_index(batch_op.f('ix_card_links_created_by'))
batch_op.drop_index(batch_op.f('ix_card_links_child_card_id'))
op.drop_table('card_links')
# ### end Alembic commands ###