
- Created FastAPI application with SQLite database - Implemented cart management (create, get, add items, remove items, clear) - Added checkout functionality with payment processing simulation - Set up database models using SQLAlchemy with Cart and CartItem tables - Configured Alembic for database migrations - Added comprehensive API documentation and examples - Included health endpoint and CORS support - Formatted code with ruff linting
71 lines
2.1 KiB
Python
71 lines
2.1 KiB
Python
"""Initial migration
|
|
|
|
Revision ID: 001
|
|
Revises:
|
|
Create Date: 2025-07-21 10:00:00.000000
|
|
|
|
"""
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = "001"
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# Create carts table
|
|
op.create_table(
|
|
"carts",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("user_id", sa.String(), nullable=True),
|
|
sa.Column("status", 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),
|
|
server_default=sa.text("(CURRENT_TIMESTAMP)"),
|
|
nullable=True,
|
|
),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index(op.f("ix_carts_id"), "carts", ["id"], unique=False)
|
|
op.create_index(op.f("ix_carts_user_id"), "carts", ["user_id"], unique=False)
|
|
|
|
# Create cart_items table
|
|
op.create_table(
|
|
"cart_items",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("cart_id", sa.Integer(), nullable=True),
|
|
sa.Column("product_id", sa.String(), nullable=True),
|
|
sa.Column("product_name", sa.String(), nullable=True),
|
|
sa.Column("price", sa.Float(), nullable=True),
|
|
sa.Column("quantity", sa.Integer(), nullable=True),
|
|
sa.ForeignKeyConstraint(
|
|
["cart_id"],
|
|
["carts.id"],
|
|
),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index(op.f("ix_cart_items_id"), "cart_items", ["id"], unique=False)
|
|
op.create_index(
|
|
op.f("ix_cart_items_product_id"), "cart_items", ["product_id"], unique=False
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index(op.f("ix_cart_items_product_id"), table_name="cart_items")
|
|
op.drop_index(op.f("ix_cart_items_id"), table_name="cart_items")
|
|
op.drop_table("cart_items")
|
|
op.drop_index(op.f("ix_carts_user_id"), table_name="carts")
|
|
op.drop_index(op.f("ix_carts_id"), table_name="carts")
|
|
op.drop_table("carts")
|