|
| 1 | +"""Initial migration |
| 2 | +
|
| 3 | +Revision ID: c2ba8ccc9a6f |
| 4 | +Revises: |
| 5 | +Create Date: 2025-01-17 17:06:38.552656 |
| 6 | +
|
| 7 | +""" |
| 8 | +from alembic import op |
| 9 | +import sqlalchemy as sa |
| 10 | + |
| 11 | + |
| 12 | +# revision identifiers, used by Alembic. |
| 13 | +revision = 'c2ba8ccc9a6f' |
| 14 | +down_revision = None |
| 15 | +branch_labels = None |
| 16 | +depends_on = None |
| 17 | + |
| 18 | + |
| 19 | +def upgrade(): |
| 20 | + # ### commands auto generated by Alembic - please adjust! ### |
| 21 | + op.create_table('category', |
| 22 | + sa.Column('id', sa.Integer(), nullable=False), |
| 23 | + sa.Column('name', sa.String(length=200), nullable=False), |
| 24 | + sa.Column('created_at', sa.DateTime(), nullable=True), |
| 25 | + sa.PrimaryKeyConstraint('id', name=op.f('category_pkey')), |
| 26 | + sa.UniqueConstraint('name', name=op.f('category_name_key')) |
| 27 | + ) |
| 28 | + op.create_table('product', |
| 29 | + sa.Column('id', sa.Integer(), nullable=False), |
| 30 | + sa.Column('name', sa.String(length=200), nullable=False), |
| 31 | + sa.Column('description', sa.String(length=500), nullable=True), |
| 32 | + sa.Column('created_at', sa.DateTime(), nullable=True), |
| 33 | + sa.PrimaryKeyConstraint('id', name=op.f('product_pkey')), |
| 34 | + sa.UniqueConstraint('name', name=op.f('product_name_key')) |
| 35 | + ) |
| 36 | + op.create_table('subcategory', |
| 37 | + sa.Column('id', sa.Integer(), nullable=False), |
| 38 | + sa.Column('name', sa.String(length=200), nullable=False), |
| 39 | + sa.Column('created_at', sa.DateTime(), nullable=True), |
| 40 | + sa.PrimaryKeyConstraint('id', name=op.f('subcategory_pkey')), |
| 41 | + sa.UniqueConstraint('name', name=op.f('subcategory_name_key')) |
| 42 | + ) |
| 43 | + op.create_table('category_subcategory', |
| 44 | + sa.Column('category_id', sa.Integer(), nullable=True), |
| 45 | + sa.Column('subcategory_id', sa.Integer(), nullable=True), |
| 46 | + sa.ForeignKeyConstraint(['category_id'], ['category.id'], name=op.f('category_subcategory_category_id_fkey')), |
| 47 | + sa.ForeignKeyConstraint(['subcategory_id'], ['subcategory.id'], name=op.f('category_subcategory_subcategory_id_fkey')) |
| 48 | + ) |
| 49 | + op.create_table('subcategory_product', |
| 50 | + sa.Column('subcategory_id', sa.Integer(), nullable=True), |
| 51 | + sa.Column('product_id', sa.Integer(), nullable=True), |
| 52 | + sa.ForeignKeyConstraint(['product_id'], ['product.id'], name=op.f('subcategory_product_product_id_fkey')), |
| 53 | + sa.ForeignKeyConstraint(['subcategory_id'], ['subcategory.id'], name=op.f('subcategory_product_subcategory_id_fkey')) |
| 54 | + ) |
| 55 | + # ### end Alembic commands ### |
| 56 | + |
| 57 | + |
| 58 | +def downgrade(): |
| 59 | + # ### commands auto generated by Alembic - please adjust! ### |
| 60 | + op.drop_table('subcategory_product') |
| 61 | + op.drop_table('category_subcategory') |
| 62 | + op.drop_table('subcategory') |
| 63 | + op.drop_table('product') |
| 64 | + op.drop_table('category') |
| 65 | + # ### end Alembic commands ### |
0 commit comments