
This commit includes: - Project structure setup with FastAPI - Database models with SQLAlchemy (users, products, categories, orders) - SQLite database configuration - Alembic migration scripts - API endpoints for authentication, users, products, categories, and orders - JWT authentication - Comprehensive documentation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
113 lines
5.1 KiB
Python
113 lines
5.1 KiB
Python
"""Initial
|
|
|
|
Revision ID: 01_initial
|
|
Revises:
|
|
Create Date: 2025-05-11
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.dialects import sqlite
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = '01_initial'
|
|
down_revision: Union[str, None] = None
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
# Create users table
|
|
op.create_table('users',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('email', sa.String(), nullable=False),
|
|
sa.Column('username', sa.String(), nullable=False),
|
|
sa.Column('hashed_password', sa.String(), nullable=False),
|
|
sa.Column('full_name', sa.String(), nullable=True),
|
|
sa.Column('is_active', sa.Boolean(), nullable=True),
|
|
sa.Column('is_admin', sa.Boolean(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), 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)
|
|
op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
|
|
|
|
# Create categories table
|
|
op.create_table('categories',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('name', sa.String(), nullable=False),
|
|
sa.Column('description', sa.Text(), nullable=True),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_categories_id'), 'categories', ['id'], unique=False)
|
|
op.create_index(op.f('ix_categories_name'), 'categories', ['name'], unique=True)
|
|
|
|
# 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=True),
|
|
sa.Column('is_active', sa.Boolean(), nullable=True),
|
|
sa.Column('category_id', sa.Integer(), nullable=True),
|
|
sa.Column('image_url', sa.String(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.ForeignKeyConstraint(['category_id'], ['categories.id'], ),
|
|
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=True),
|
|
sa.Column('status', sa.Enum('PENDING', 'PROCESSING', 'SHIPPED', 'DELIVERED', 'CANCELLED', name='orderstatus'), nullable=True),
|
|
sa.Column('total_amount', sa.Float(), nullable=True),
|
|
sa.Column('shipping_address', sa.String(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), 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=True),
|
|
sa.Column('product_id', sa.Integer(), nullable=True),
|
|
sa.Column('quantity', sa.Integer(), nullable=True),
|
|
sa.Column('price', sa.Float(), 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)
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
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_categories_name'), table_name='categories')
|
|
op.drop_index(op.f('ix_categories_id'), table_name='categories')
|
|
op.drop_table('categories')
|
|
op.drop_index(op.f('ix_users_username'), table_name='users')
|
|
op.drop_index(op.f('ix_users_id'), table_name='users')
|
|
op.drop_index(op.f('ix_users_email'), table_name='users')
|
|
op.drop_table('users')
|
|
# ### end Alembic commands ### |