Add migration for Product

This commit is contained in:
Backend IM Bot 2025-03-26 14:12:19 +00:00
parent 621db14717
commit 6e1d33dfe7

View File

@ -0,0 +1,39 @@
"""create products 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(
'products',
sa.Column('id', sa.String(), primary_key=True, default=lambda: str(uuid.uuid4())),
sa.Column('name', sa.String(), nullable=False),
sa.Column('description', sa.String(), nullable=True),
sa.Column('price', sa.Float(), nullable=False),
sa.Column('stock', sa.Integer(), nullable=False, server_default='0'),
sa.Column('sku', sa.String(), nullable=False),
sa.Column('is_active', sa.Boolean(), server_default='true'),
sa.Column('created_at', sa.DateTime(), server_default=func.now()),
sa.Column('updated_at', sa.DateTime(), server_default=func.now(), onupdate=func.now()),
sa.PrimaryKeyConstraint('id')
)
op.create_index('ix_products_name', 'products', ['name'])
op.create_index('ix_products_sku', 'products', ['sku'], unique=True)
def downgrade():
op.drop_index('ix_products_sku', 'products')
op.drop_index('ix_products_name', 'products')
op.drop_table('products')