
- Set up FastAPI application with CORS and health check endpoint - Create SQLite database models for inventory items, categories, and suppliers - Implement complete CRUD API endpoints for all entities - Add low-stock monitoring functionality - Configure Alembic for database migrations - Set up Ruff for code linting and formatting - Include comprehensive API documentation and README
76 lines
3.1 KiB
Python
76 lines
3.1 KiB
Python
"""Initial migration
|
|
|
|
Revision ID: 001
|
|
Revises:
|
|
Create Date: 2024-01-01 00:00:00.000000
|
|
|
|
"""
|
|
import sqlalchemy as sa
|
|
|
|
from alembic import op
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '001'
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# Create categories table
|
|
op.create_table('categories',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('name', sa.String(length=100), nullable=False),
|
|
sa.Column('description', sa.Text(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(), 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 suppliers table
|
|
op.create_table('suppliers',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('name', sa.String(length=200), nullable=False),
|
|
sa.Column('contact_person', sa.String(length=100), nullable=True),
|
|
sa.Column('email', sa.String(length=100), nullable=True),
|
|
sa.Column('phone', sa.String(length=20), nullable=True),
|
|
sa.Column('address', sa.Text(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_suppliers_id'), 'suppliers', ['id'], unique=False)
|
|
op.create_index(op.f('ix_suppliers_name'), 'suppliers', ['name'], unique=True)
|
|
|
|
# Create inventory_items table
|
|
op.create_table('inventory_items',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('name', sa.String(length=200), nullable=False),
|
|
sa.Column('sku', sa.String(length=50), nullable=False),
|
|
sa.Column('description', sa.Text(), nullable=True),
|
|
sa.Column('quantity', sa.Integer(), nullable=True),
|
|
sa.Column('unit_price', sa.Float(), nullable=False),
|
|
sa.Column('minimum_stock', sa.Integer(), nullable=True),
|
|
sa.Column('category_id', sa.Integer(), nullable=True),
|
|
sa.Column('supplier_id', sa.Integer(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
|
sa.ForeignKeyConstraint(['category_id'], ['categories.id'], ),
|
|
sa.ForeignKeyConstraint(['supplier_id'], ['suppliers.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_inventory_items_id'), 'inventory_items', ['id'], unique=False)
|
|
op.create_index(op.f('ix_inventory_items_sku'), 'inventory_items', ['sku'], unique=True)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index(op.f('ix_inventory_items_sku'), table_name='inventory_items')
|
|
op.drop_index(op.f('ix_inventory_items_id'), table_name='inventory_items')
|
|
op.drop_table('inventory_items')
|
|
op.drop_index(op.f('ix_suppliers_name'), table_name='suppliers')
|
|
op.drop_index(op.f('ix_suppliers_id'), table_name='suppliers')
|
|
op.drop_table('suppliers')
|
|
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')
|