Automated Action 447799c9a0 Implement complete FastAPI inventory management system for small businesses
Features implemented:
- Product management with CRUD operations
- Category and supplier management
- Stock movement tracking with automatic updates
- Inventory reports and analytics
- SQLite database with Alembic migrations
- Health monitoring endpoints
- CORS configuration for API access
- Comprehensive API documentation
- Code quality with Ruff linting and formatting

The system provides a complete backend solution for small business inventory management with proper database relationships, stock tracking, and reporting capabilities.
2025-07-23 09:07:46 +00:00

111 lines
4.3 KiB
Python

"""Initial migration
Revision ID: 001
Revises:
Create Date: 2024-01-01 00:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
revision = "001"
down_revision = None
branch_labels = None
depends_on = None
def upgrade() -> None:
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.Column("updated_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)
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.Column("updated_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=False)
op.create_table(
"products",
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("price", sa.Float(), nullable=False),
sa.Column("cost", sa.Float(), nullable=True),
sa.Column("quantity_in_stock", sa.Integer(), nullable=True),
sa.Column("minimum_stock_level", 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_products_id"), "products", ["id"], unique=False)
op.create_index(op.f("ix_products_name"), "products", ["name"], unique=False)
op.create_index(op.f("ix_products_sku"), "products", ["sku"], unique=True)
op.create_table(
"stock_movements",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("product_id", sa.Integer(), nullable=False),
sa.Column(
"movement_type",
sa.Enum("IN", "OUT", "ADJUSTMENT", name="movementtype"),
nullable=False,
),
sa.Column("quantity", sa.Integer(), nullable=False),
sa.Column("reference", sa.String(length=100), nullable=True),
sa.Column("notes", sa.Text(), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(
["product_id"],
["products.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_stock_movements_id"), "stock_movements", ["id"], unique=False
)
def downgrade() -> None:
op.drop_index(op.f("ix_stock_movements_id"), table_name="stock_movements")
op.drop_table("stock_movements")
op.drop_index(op.f("ix_products_sku"), table_name="products")
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_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")