pyfedi/migrations/versions/fd5d3a9cb584_community_topics.py
2024-01-04 16:09:22 +13:00

45 lines
1.3 KiB
Python

"""community topics
Revision ID: fd5d3a9cb584
Revises: 328c9990e53e
Create Date: 2024-01-04 15:13:29.499990
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'fd5d3a9cb584'
down_revision = '328c9990e53e'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('topic',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=50), nullable=True),
sa.Column('num_communities', sa.Integer(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('community', schema=None) as batch_op:
batch_op.add_column(sa.Column('topic_id', sa.Integer(), nullable=True))
batch_op.create_index(batch_op.f('ix_community_topic_id'), ['topic_id'], unique=False)
batch_op.create_foreign_key(None, 'topic', ['topic_id'], ['id'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('community', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.drop_index(batch_op.f('ix_community_topic_id'))
batch_op.drop_column('topic_id')
op.drop_table('topic')
# ### end Alembic commands ###