
- Created complete RESTful API for inventory management - Set up database models for items, categories, suppliers, and transactions - Implemented user authentication with JWT tokens - Added transaction tracking for inventory movements - Created comprehensive API endpoints for all CRUD operations - Set up Alembic for database migrations - Added input validation and error handling - Created detailed documentation in README
131 lines
5.9 KiB
Python
131 lines
5.9 KiB
Python
"""Initial tables
|
|
|
|
Revision ID: 0001
|
|
Revises:
|
|
Create Date: 2023-08-01 00:00:00.000000
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '0001'
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
# Create User table
|
|
op.create_table(
|
|
'user',
|
|
sa.Column('id', sa.String(), 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, default=True),
|
|
sa.Column('is_superuser', sa.Boolean(), nullable=True, default=False),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=True)
|
|
op.create_index(op.f('ix_user_full_name'), 'user', ['full_name'], unique=False)
|
|
op.create_index(op.f('ix_user_id'), 'user', ['id'], unique=False)
|
|
|
|
# Create Category table
|
|
op.create_table(
|
|
'category',
|
|
sa.Column('id', sa.String(), nullable=False),
|
|
sa.Column('name', sa.String(), nullable=False),
|
|
sa.Column('description', sa.Text(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_category_id'), 'category', ['id'], unique=False)
|
|
op.create_index(op.f('ix_category_name'), 'category', ['name'], unique=False)
|
|
|
|
# Create Supplier table
|
|
op.create_table(
|
|
'supplier',
|
|
sa.Column('id', sa.String(), 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('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_supplier_id'), 'supplier', ['id'], unique=False)
|
|
op.create_index(op.f('ix_supplier_name'), 'supplier', ['name'], unique=False)
|
|
|
|
# Create Item table
|
|
op.create_table(
|
|
'item',
|
|
sa.Column('id', sa.String(), 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('quantity', sa.Integer(), nullable=False, default=0),
|
|
sa.Column('unit_price', sa.Float(), nullable=False),
|
|
sa.Column('location', sa.String(), nullable=True),
|
|
sa.Column('min_stock_level', sa.Integer(), nullable=True, default=0),
|
|
sa.Column('category_id', sa.String(), nullable=True),
|
|
sa.Column('supplier_id', sa.String(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.ForeignKeyConstraint(['category_id'], ['category.id'], ),
|
|
sa.ForeignKeyConstraint(['supplier_id'], ['supplier.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_item_id'), 'item', ['id'], unique=False)
|
|
op.create_index(op.f('ix_item_name'), 'item', ['name'], unique=False)
|
|
op.create_index(op.f('ix_item_sku'), 'item', ['sku'], unique=True)
|
|
|
|
# Create Transaction table
|
|
op.create_table(
|
|
'transaction',
|
|
sa.Column('id', sa.String(), nullable=False),
|
|
sa.Column('transaction_type', sa.String(), nullable=False),
|
|
sa.Column('quantity', sa.Integer(), nullable=False),
|
|
sa.Column('unit_price', sa.Float(), nullable=False),
|
|
sa.Column('total_price', sa.Float(), nullable=False),
|
|
sa.Column('reference_number', sa.String(), nullable=True),
|
|
sa.Column('notes', sa.Text(), nullable=True),
|
|
sa.Column('item_id', sa.String(), nullable=False),
|
|
sa.Column('user_id', sa.String(), nullable=False),
|
|
sa.Column('transaction_date', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.ForeignKeyConstraint(['item_id'], ['item.id'], ),
|
|
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_transaction_id'), 'transaction', ['id'], unique=False)
|
|
|
|
|
|
def downgrade():
|
|
op.drop_index(op.f('ix_transaction_id'), table_name='transaction')
|
|
op.drop_table('transaction')
|
|
|
|
op.drop_index(op.f('ix_item_sku'), table_name='item')
|
|
op.drop_index(op.f('ix_item_name'), table_name='item')
|
|
op.drop_index(op.f('ix_item_id'), table_name='item')
|
|
op.drop_table('item')
|
|
|
|
op.drop_index(op.f('ix_supplier_name'), table_name='supplier')
|
|
op.drop_index(op.f('ix_supplier_id'), table_name='supplier')
|
|
op.drop_table('supplier')
|
|
|
|
op.drop_index(op.f('ix_category_name'), table_name='category')
|
|
op.drop_index(op.f('ix_category_id'), table_name='category')
|
|
op.drop_table('category')
|
|
|
|
op.drop_index(op.f('ix_user_id'), table_name='user')
|
|
op.drop_index(op.f('ix_user_full_name'), table_name='user')
|
|
op.drop_index(op.f('ix_user_email'), table_name='user')
|
|
op.drop_table('user') |