106 lines
4.9 KiB
Python
106 lines
4.9 KiB
Python
"""add epic and wiki models
|
|
|
|
Revision ID: 6fc439155ced
|
|
Revises: e9515e29ef8b
|
|
Create Date: 2026-03-22 00:24:26.645867
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '6fc439155ced'
|
|
down_revision = 'e9515e29ef8b'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.create_table('epics',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('name', sa.String(length=200), nullable=False),
|
|
sa.Column('description', sa.Text(), nullable=True),
|
|
sa.Column('content', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
|
|
sa.Column('color', sa.String(length=7), nullable=True),
|
|
sa.Column('closed', sa.Boolean(), nullable=True),
|
|
sa.Column('pos', sa.Float(), nullable=True),
|
|
sa.Column('depth_limit', sa.Integer(), nullable=True),
|
|
sa.Column('board_id', sa.Integer(), nullable=False),
|
|
sa.Column('parent_epic_id', sa.Integer(), nullable=True),
|
|
sa.Column('date_last_activity', sa.DateTime(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
|
sa.Column('metrics', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
|
|
sa.ForeignKeyConstraint(['board_id'], ['boards.id'], ondelete='CASCADE'),
|
|
sa.ForeignKeyConstraint(['parent_epic_id'], ['epics.id'], ondelete='SET NULL'),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
with op.batch_alter_table('epics', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_epics_board_id'), ['board_id'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_epics_closed'), ['closed'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_epics_name'), ['name'], unique=False)
|
|
|
|
op.create_table('wikis',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('name', sa.String(length=200), nullable=False),
|
|
sa.Column('slug', sa.String(length=255), nullable=True),
|
|
sa.Column('content', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
|
|
sa.Column('summary', sa.Text(), nullable=True),
|
|
sa.Column('category', sa.String(length=100), nullable=True),
|
|
sa.Column('board_id', sa.Integer(), nullable=False),
|
|
sa.Column('created_by', sa.Integer(), nullable=True),
|
|
sa.Column('updated_by', sa.Integer(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
|
sa.Column('tags', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
|
|
sa.ForeignKeyConstraint(['board_id'], ['boards.id'], ondelete='CASCADE'),
|
|
sa.ForeignKeyConstraint(['created_by'], ['users.id'], ondelete='SET NULL'),
|
|
sa.ForeignKeyConstraint(['updated_by'], ['users.id'], ondelete='SET NULL'),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
with op.batch_alter_table('wikis', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_wikis_board_id'), ['board_id'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_wikis_name'), ['name'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_wikis_slug'), ['slug'], unique=False)
|
|
|
|
op.create_table('wiki_entity_links',
|
|
sa.Column('wiki_id', sa.Integer(), nullable=False),
|
|
sa.Column('entity_type', sa.String(length=50), nullable=False),
|
|
sa.Column('entity_id', sa.Integer(), nullable=False),
|
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
|
sa.Column('linked_by', sa.Integer(), nullable=True),
|
|
sa.ForeignKeyConstraint(['linked_by'], ['users.id'], ondelete='SET NULL'),
|
|
sa.ForeignKeyConstraint(['wiki_id'], ['wikis.id'], ondelete='CASCADE'),
|
|
sa.PrimaryKeyConstraint('wiki_id')
|
|
)
|
|
with op.batch_alter_table('cards', schema=None) as batch_op:
|
|
batch_op.add_column(sa.Column('epic_id', sa.Integer(), nullable=True))
|
|
batch_op.create_index(batch_op.f('ix_cards_epic_id'), ['epic_id'], unique=False)
|
|
batch_op.create_foreign_key(None, 'epics', ['epic_id'], ['id'], ondelete='SET NULL')
|
|
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade():
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
with op.batch_alter_table('cards', schema=None) as batch_op:
|
|
batch_op.drop_constraint(None, type_='foreignkey')
|
|
batch_op.drop_index(batch_op.f('ix_cards_epic_id'))
|
|
batch_op.drop_column('epic_id')
|
|
|
|
op.drop_table('wiki_entity_links')
|
|
with op.batch_alter_table('wikis', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_wikis_slug'))
|
|
batch_op.drop_index(batch_op.f('ix_wikis_name'))
|
|
batch_op.drop_index(batch_op.f('ix_wikis_board_id'))
|
|
|
|
op.drop_table('wikis')
|
|
with op.batch_alter_table('epics', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_epics_name'))
|
|
batch_op.drop_index(batch_op.f('ix_epics_closed'))
|
|
batch_op.drop_index(batch_op.f('ix_epics_board_id'))
|
|
|
|
op.drop_table('epics')
|
|
# ### end Alembic commands ###
|