Updating to support categories
This commit is contained in:
46
backend/alembic/versions/2d2d4523082b_add_category_table.py
Executable file
46
backend/alembic/versions/2d2d4523082b_add_category_table.py
Executable file
@@ -0,0 +1,46 @@
|
||||
"""add category table
|
||||
|
||||
Revision ID: 2d2d4523082b
|
||||
Revises:
|
||||
Create Date: 2023-03-09 20:29:44.081609
|
||||
|
||||
"""
|
||||
import sqlalchemy as sa
|
||||
import sqlmodel
|
||||
|
||||
from alembic import op
|
||||
from src.models.category import Category
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '2d2d4523082b'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# create category table
|
||||
Category.__table__.create(bind=op.get_bind())
|
||||
|
||||
op.bulk_insert(
|
||||
Category.__table__,
|
||||
[
|
||||
{"id": 1, "name": "Alfabet"},
|
||||
]
|
||||
)
|
||||
|
||||
with op.batch_alter_table('sign', schema=None) as batch_op:
|
||||
# create column category_id
|
||||
batch_op.add_column(sa.Column('category_id', sa.Integer(), nullable=True, default=1))
|
||||
batch_op.create_foreign_key("sign_category", 'category', ['category_id'], ['id'])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('sign', schema=None) as batch_op:
|
||||
batch_op.drop_constraint("sign_category", type_='foreignkey')
|
||||
batch_op.drop_column('category_id')
|
||||
# drop category table
|
||||
Category.__table__.drop(bind=op.get_bind())
|
||||
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user