
- Added comprehensive book management with CRUD operations - Implemented inventory tracking with stock management and reservations - Created order management system with status tracking - Integrated Stripe payment processing with payment intents - Added SQLite database with SQLAlchemy ORM and Alembic migrations - Implemented health check and API documentation endpoints - Added comprehensive error handling and validation - Configured CORS middleware for frontend integration
92 lines
4.1 KiB
Python
92 lines
4.1 KiB
Python
"""Initial migration
|
|
|
|
Revision ID: 001
|
|
Revises:
|
|
Create Date: 2024-01-01 12: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 books table
|
|
op.create_table('books',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('title', sa.String(length=255), nullable=False),
|
|
sa.Column('author', sa.String(length=255), nullable=False),
|
|
sa.Column('isbn', sa.String(length=13), nullable=False),
|
|
sa.Column('description', sa.Text(), nullable=True),
|
|
sa.Column('price', sa.Float(), nullable=False),
|
|
sa.Column('category', sa.String(length=100), nullable=False),
|
|
sa.Column('publisher', sa.String(length=255), nullable=True),
|
|
sa.Column('publication_date', sa.DateTime(), nullable=True),
|
|
sa.Column('pages', sa.Integer(), nullable=True),
|
|
sa.Column('language', sa.String(length=50), nullable=True),
|
|
sa.Column('is_active', 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_books_id'), 'books', ['id'], unique=False)
|
|
op.create_index(op.f('ix_books_isbn'), 'books', ['isbn'], unique=True)
|
|
op.create_index(op.f('ix_books_title'), 'books', ['title'], unique=False)
|
|
|
|
# Create inventory table
|
|
op.create_table('inventory',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('book_id', sa.Integer(), nullable=False),
|
|
sa.Column('quantity', sa.Integer(), nullable=False),
|
|
sa.Column('reserved_quantity', sa.Integer(), nullable=False),
|
|
sa.Column('reorder_level', sa.Integer(), nullable=False),
|
|
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(['book_id'], ['books.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_inventory_id'), 'inventory', ['id'], unique=False)
|
|
|
|
# Create orders table
|
|
op.create_table('orders',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('customer_email', sa.String(length=255), nullable=False),
|
|
sa.Column('customer_name', sa.String(length=255), nullable=False),
|
|
sa.Column('customer_address', sa.Text(), nullable=False),
|
|
sa.Column('total_amount', sa.Float(), nullable=False),
|
|
sa.Column('status', sa.Enum('PENDING', 'CONFIRMED', 'SHIPPED', 'DELIVERED', 'CANCELLED', name='orderstatus'), nullable=True),
|
|
sa.Column('stripe_payment_intent_id', sa.String(length=255), 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_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('book_id', sa.Integer(), nullable=False),
|
|
sa.Column('quantity', sa.Integer(), nullable=False),
|
|
sa.Column('price', sa.Float(), nullable=False),
|
|
sa.ForeignKeyConstraint(['book_id'], ['books.id'], ),
|
|
sa.ForeignKeyConstraint(['order_id'], ['orders.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_order_items_id'), 'order_items', ['id'], unique=False)
|
|
|
|
def downgrade() -> None:
|
|
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_inventory_id'), table_name='inventory')
|
|
op.drop_table('inventory')
|
|
op.drop_index(op.f('ix_books_title'), table_name='books')
|
|
op.drop_index(op.f('ix_books_isbn'), table_name='books')
|
|
op.drop_index(op.f('ix_books_id'), table_name='books')
|
|
op.drop_table('books') |