Automated Action e8172f2bc2 Implement complete FastAPI inventory management system
- Set up project structure with FastAPI and SQLite
- Created database models for users, categories, suppliers, items, and stock transactions
- Implemented Alembic for database migrations with proper absolute paths
- Built comprehensive CRUD operations for all entities
- Added JWT-based authentication and authorization system
- Created RESTful API endpoints for all inventory operations
- Implemented search, filtering, and low stock alerts
- Added health check endpoint and base URL response
- Configured CORS for all origins
- Set up Ruff for code linting and formatting
- Updated README with comprehensive documentation and usage examples

The system provides complete inventory management functionality for small businesses
including product tracking, supplier management, stock transactions, and reporting.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-18 10:55:22 +00:00

143 lines
5.7 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 users table
op.create_table(
"users",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("email", 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_superuser", sa.Boolean(), 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_users_email"), "users", ["email"], unique=True)
op.create_index(op.f("ix_users_id"), "users", ["id"], unique=False)
# 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.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)
# Create suppliers table
op.create_table(
"suppliers",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("name", sa.String(), nullable=False),
sa.Column("contact_person", sa.String(), nullable=True),
sa.Column("email", sa.String(), nullable=True),
sa.Column("phone", sa.String(), 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=True)
# Create items table
op.create_table(
"items",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("name", sa.String(), nullable=False),
sa.Column("description", sa.Text(), nullable=True),
sa.Column("sku", sa.String(), nullable=False),
sa.Column("barcode", sa.String(), nullable=True),
sa.Column("unit_price", sa.Float(), nullable=False),
sa.Column("cost_price", sa.Float(), nullable=True),
sa.Column("quantity_in_stock", sa.Integer(), nullable=True),
sa.Column("minimum_stock_level", sa.Integer(), nullable=True),
sa.Column("maximum_stock_level", sa.Integer(), nullable=True),
sa.Column("reorder_point", sa.Integer(), nullable=True),
sa.Column("is_active", sa.Boolean(), 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_items_barcode"), "items", ["barcode"], unique=True)
op.create_index(op.f("ix_items_id"), "items", ["id"], unique=False)
op.create_index(op.f("ix_items_name"), "items", ["name"], unique=False)
op.create_index(op.f("ix_items_sku"), "items", ["sku"], unique=True)
# Create stock_transactions table
op.create_table(
"stock_transactions",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("item_id", sa.Integer(), nullable=False),
sa.Column(
"transaction_type",
sa.Enum("IN", "OUT", "ADJUSTMENT", name="transactiontype"),
nullable=False,
),
sa.Column("quantity", sa.Integer(), nullable=False),
sa.Column("unit_cost", sa.Float(), nullable=True),
sa.Column("reference_number", sa.String(), nullable=True),
sa.Column("notes", sa.Text(), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(
["item_id"],
["items.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_stock_transactions_id"), "stock_transactions", ["id"], unique=False
)
def downgrade() -> None:
op.drop_index(op.f("ix_stock_transactions_id"), table_name="stock_transactions")
op.drop_table("stock_transactions")
op.drop_index(op.f("ix_items_sku"), table_name="items")
op.drop_index(op.f("ix_items_name"), table_name="items")
op.drop_index(op.f("ix_items_id"), table_name="items")
op.drop_index(op.f("ix_items_barcode"), table_name="items")
op.drop_table("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")
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")