
- Create project structure with FastAPI and SQLAlchemy - Implement database models for items, categories, suppliers, and stock movements - Add CRUD operations for all models - Configure Alembic for database migrations - Create RESTful API endpoints for inventory management - Add health endpoint for system monitoring - Update README with setup and usage instructions generated with BackendIM... (backend.im)
95 lines
4.2 KiB
Python
95 lines
4.2 KiB
Python
"""initial tables
|
|
|
|
Revision ID: 0001
|
|
Revises:
|
|
Create Date: 2025-05-12
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.sql import func
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '0001'
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
# 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.String(), nullable=True),
|
|
sa.Column('is_active', sa.Boolean(), nullable=True, default=True),
|
|
sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=func.now(), nullable=True),
|
|
sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=func.now(), nullable=True),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('name')
|
|
)
|
|
op.create_index(op.f('ix_categories_id'), 'categories', ['id'], unique=False)
|
|
|
|
# Create suppliers table
|
|
op.create_table('suppliers',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('name', sa.String(), nullable=False),
|
|
sa.Column('contact_name', sa.String(), nullable=True),
|
|
sa.Column('email', sa.String(), nullable=True),
|
|
sa.Column('phone', sa.String(), nullable=True),
|
|
sa.Column('address', sa.String(), nullable=True),
|
|
sa.Column('is_active', sa.Boolean(), nullable=True, default=True),
|
|
sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=func.now(), nullable=True),
|
|
sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=func.now(), nullable=True),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('name')
|
|
)
|
|
op.create_index(op.f('ix_suppliers_id'), 'suppliers', ['id'], unique=False)
|
|
|
|
# Create items table
|
|
op.create_table('items',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('name', sa.String(), nullable=False),
|
|
sa.Column('sku', sa.String(), nullable=False),
|
|
sa.Column('description', sa.String(), nullable=True),
|
|
sa.Column('unit_price', sa.Float(), nullable=False, default=0.0),
|
|
sa.Column('quantity', sa.Integer(), nullable=False, default=0),
|
|
sa.Column('reorder_level', sa.Integer(), nullable=False, default=0),
|
|
sa.Column('category_id', sa.Integer(), nullable=True),
|
|
sa.Column('supplier_id', sa.Integer(), nullable=True),
|
|
sa.Column('is_active', sa.Boolean(), nullable=True, default=True),
|
|
sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=func.now(), nullable=True),
|
|
sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=func.now(), nullable=True),
|
|
sa.ForeignKeyConstraint(['category_id'], ['categories.id'], ),
|
|
sa.ForeignKeyConstraint(['supplier_id'], ['suppliers.id'], ),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('sku')
|
|
)
|
|
op.create_index(op.f('ix_items_id'), 'items', ['id'], unique=False)
|
|
|
|
# Create stock_movements table
|
|
op.create_table('stock_movements',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('item_id', sa.Integer(), nullable=False),
|
|
sa.Column('quantity', sa.Integer(), nullable=False),
|
|
sa.Column('movement_type', sa.Enum('purchase', 'sale', 'adjustment', 'return', name='movementtype'), nullable=False),
|
|
sa.Column('reference', sa.String(), nullable=True),
|
|
sa.Column('notes', sa.String(), nullable=True),
|
|
sa.Column('unit_price', sa.Float(), nullable=True),
|
|
sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=func.now(), nullable=True),
|
|
sa.ForeignKeyConstraint(['item_id'], ['items.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_stock_movements_id'), 'stock_movements', ['id'], unique=False)
|
|
|
|
|
|
def downgrade():
|
|
op.drop_index(op.f('ix_stock_movements_id'), table_name='stock_movements')
|
|
op.drop_table('stock_movements')
|
|
op.drop_index(op.f('ix_items_id'), table_name='items')
|
|
op.drop_table('items')
|
|
op.drop_index(op.f('ix_suppliers_id'), table_name='suppliers')
|
|
op.drop_table('suppliers')
|
|
op.drop_index(op.f('ix_categories_id'), table_name='categories')
|
|
op.drop_table('categories') |