
- Implemented user authentication with JWT tokens - Created product management endpoints - Added shopping cart functionality - Implemented order management system - Setup database models with SQLAlchemy - Created alembic migrations - Added health check endpoint generated with BackendIM... (backend.im)
112 lines
5.1 KiB
Python
112 lines
5.1 KiB
Python
"""initial migration
|
|
|
|
Revision ID: 20250513_000001
|
|
Revises:
|
|
Create Date: 2025-05-13 00:00:01.000000
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '20250513_000001'
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
# Create users table
|
|
op.create_table(
|
|
'users',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('email', sa.String(), nullable=False),
|
|
sa.Column('password', sa.String(), nullable=False),
|
|
sa.Column('full_name', sa.String(), nullable=True),
|
|
sa.Column('is_active', sa.Boolean(), nullable=True, default=True),
|
|
sa.Column('is_admin', sa.Boolean(), nullable=True, default=False),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=True),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
|
|
op.create_index(op.f('ix_users_id'), 'users', ['id'], unique=False)
|
|
|
|
# Create products table
|
|
op.create_table(
|
|
'products',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('name', sa.String(), nullable=False),
|
|
sa.Column('description', sa.Text(), nullable=True),
|
|
sa.Column('price', sa.Float(), nullable=False),
|
|
sa.Column('stock', sa.Integer(), nullable=False, default=0),
|
|
sa.Column('image_url', sa.String(), nullable=True),
|
|
sa.Column('is_active', sa.Boolean(), nullable=True, default=True),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=True),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_products_id'), 'products', ['id'], unique=False)
|
|
op.create_index(op.f('ix_products_name'), 'products', ['name'], unique=False)
|
|
|
|
# Create orders table
|
|
op.create_table(
|
|
'orders',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('user_id', sa.Integer(), nullable=False),
|
|
sa.Column('total_amount', sa.Float(), nullable=False),
|
|
sa.Column('status', sa.String(), nullable=False, default='pending'),
|
|
sa.Column('shipping_address', sa.String(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=True),
|
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_orders_id'), 'orders', ['id'], unique=False)
|
|
|
|
# Create order_items table
|
|
op.create_table(
|
|
'order_items',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('order_id', sa.Integer(), nullable=False),
|
|
sa.Column('product_id', sa.Integer(), nullable=False),
|
|
sa.Column('quantity', sa.Integer(), nullable=False),
|
|
sa.Column('unit_price', sa.Float(), nullable=False),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=True),
|
|
sa.ForeignKeyConstraint(['order_id'], ['orders.id'], ),
|
|
sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_order_items_id'), 'order_items', ['id'], unique=False)
|
|
|
|
# Create cart_items table
|
|
op.create_table(
|
|
'cart_items',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('user_id', sa.Integer(), nullable=False),
|
|
sa.Column('product_id', sa.Integer(), nullable=False),
|
|
sa.Column('quantity', sa.Integer(), nullable=False, default=1),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=True),
|
|
sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
|
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_cart_items_id'), 'cart_items', ['id'], unique=False)
|
|
|
|
|
|
def downgrade():
|
|
op.drop_index(op.f('ix_cart_items_id'), table_name='cart_items')
|
|
op.drop_table('cart_items')
|
|
op.drop_index(op.f('ix_order_items_id'), table_name='order_items')
|
|
op.drop_table('order_items')
|
|
op.drop_index(op.f('ix_orders_id'), table_name='orders')
|
|
op.drop_table('orders')
|
|
op.drop_index(op.f('ix_products_name'), table_name='products')
|
|
op.drop_index(op.f('ix_products_id'), table_name='products')
|
|
op.drop_table('products')
|
|
op.drop_index(op.f('ix_users_email'), table_name='users')
|
|
op.drop_index(op.f('ix_users_id'), table_name='users')
|
|
op.drop_table('users') |