Add migration for Pen
This commit is contained in:
parent
77f3cad537
commit
a61666fb76
45
alembic/versions/20250326_222023_82396d31_create_pen.py
Normal file
45
alembic/versions/20250326_222023_82396d31_create_pen.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
"""create pens table
|
||||||
|
|
||||||
|
Revision ID: b2c3d4e5f6g7
|
||||||
|
Revises:
|
||||||
|
Create Date: 2023-12-20 10:00:00.000000
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.sql import func
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
# revision identifiers
|
||||||
|
revision = 'b2c3d4e5f6g7'
|
||||||
|
down_revision = None
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.create_table(
|
||||||
|
'pens',
|
||||||
|
sa.Column('id', sa.String(), primary_key=True, default=lambda: str(uuid.uuid4())),
|
||||||
|
sa.Column('name', sa.String(), nullable=False),
|
||||||
|
sa.Column('brand', sa.String(), nullable=False),
|
||||||
|
sa.Column('color', sa.String(), nullable=False),
|
||||||
|
sa.Column('price', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('in_stock', sa.Boolean(), default=True),
|
||||||
|
sa.Column('description', sa.String()),
|
||||||
|
sa.Column('created_at', sa.DateTime(), server_default=sa.func.now()),
|
||||||
|
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.now(), onupdate=sa.func.now()),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create indexes
|
||||||
|
op.create_index('ix_pens_name', 'pens', ['name'])
|
||||||
|
op.create_index('ix_pens_brand', 'pens', ['brand'])
|
||||||
|
op.create_index('ix_pens_color', 'pens', ['color'])
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# Drop indexes
|
||||||
|
op.drop_index('ix_pens_color', 'pens')
|
||||||
|
op.drop_index('ix_pens_brand', 'pens')
|
||||||
|
op.drop_index('ix_pens_name', 'pens')
|
||||||
|
|
||||||
|
# Drop table
|
||||||
|
op.drop_table('pens')
|
Loading…
x
Reference in New Issue
Block a user