
- Set up project structure for FastAPI application - Create database models for items, categories, suppliers, and transactions - Set up Alembic for database migrations - Implement API endpoints for all entities - Add authentication with JWT tokens - Add health check endpoint - Create comprehensive README with documentation
129 lines
6.2 KiB
Python
129 lines
6.2 KiB
Python
"""Initial migration
|
|
|
|
Revision ID: 01_initial
|
|
Revises:
|
|
Create Date: 2023-10-23
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '01_initial'
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
# Create users table
|
|
op.create_table(
|
|
'users',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), 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.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('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
|
sa.Column('name', sa.String(), nullable=False),
|
|
sa.Column('description', sa.Text(), 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=False)
|
|
|
|
# Create suppliers table
|
|
op.create_table(
|
|
'suppliers',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), 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.Text(), nullable=True),
|
|
sa.Column('notes', sa.Text(), 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)
|
|
|
|
# Create items table
|
|
op.create_table(
|
|
'items',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
|
sa.Column('name', sa.String(), nullable=False),
|
|
sa.Column('description', sa.Text(), nullable=True),
|
|
sa.Column('sku', sa.String(), nullable=True),
|
|
sa.Column('barcode', sa.String(), nullable=True),
|
|
sa.Column('quantity', sa.Integer(), nullable=False),
|
|
sa.Column('unit_price', sa.Float(), nullable=True),
|
|
sa.Column('reorder_level', sa.Integer(), nullable=True),
|
|
sa.Column('location', sa.String(), nullable=True),
|
|
sa.Column('category_id', sa.Integer(), nullable=True),
|
|
sa.Column('supplier_id', sa.Integer(), nullable=True),
|
|
sa.Column('owner_id', sa.Integer(), nullable=False),
|
|
sa.ForeignKeyConstraint(['category_id'], ['categories.id'], ),
|
|
sa.ForeignKeyConstraint(['owner_id'], ['users.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 transactions table
|
|
op.create_table(
|
|
'transactions',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
|
sa.Column('transaction_type', sa.Enum('STOCK_IN', 'STOCK_OUT', 'ADJUSTMENT', name='transactiontype'), nullable=False),
|
|
sa.Column('quantity', sa.Integer(), nullable=False),
|
|
sa.Column('unit_price', sa.Float(), nullable=True),
|
|
sa.Column('reference', sa.String(), nullable=True),
|
|
sa.Column('notes', sa.Text(), nullable=True),
|
|
sa.Column('item_id', sa.Integer(), nullable=False),
|
|
sa.Column('user_id', sa.Integer(), nullable=False),
|
|
sa.ForeignKeyConstraint(['item_id'], ['items.id'], ),
|
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_transactions_id'), 'transactions', ['id'], unique=False)
|
|
|
|
|
|
def downgrade():
|
|
op.drop_index(op.f('ix_transactions_id'), table_name='transactions')
|
|
op.drop_table('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') |