"""smart inv

Revision ID: 057861985319
Revises: 7268a22148b7
Create Date: 2025-12-18 10:48:01.158290

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '057861985319'
down_revision: Union[str, None] = '7268a22148b7'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('companies',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('company_name', sa.String(length=255), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_companies_company_id'), 'companies', ['company_id'], unique=True)
    op.create_index(op.f('ix_companies_id'), 'companies', ['id'], unique=False)
    op.create_table('categories',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('category_id', sa.Integer(), nullable=True),
    sa.Column('category_name', sa.String(length=255), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('category_id')
    )
    op.create_index(op.f('ix_categories_company_id'), 'categories', ['company_id'], unique=False)
    op.create_index(op.f('ix_categories_id'), 'categories', ['id'], unique=False)
    op.create_table('discounts',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('discount_id', sa.Integer(), nullable=False),
    sa.Column('discount_name', sa.String(length=255), nullable=False),
    sa.Column('discount_code', sa.String(length=100), nullable=True),
    sa.Column('discount_type', sa.String(length=50), nullable=False),
    sa.Column('value', sa.Float(), nullable=False),
    sa.Column('discount_rules', sa.JSON(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_discounts_company_id'), 'discounts', ['company_id'], unique=False)
    op.create_index(op.f('ix_discounts_discount_id'), 'discounts', ['discount_id'], unique=True)
    op.create_index(op.f('ix_discounts_id'), 'discounts', ['id'], unique=False)
    op.create_table('locations',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=True),
    sa.Column('location_name', sa.String(length=255), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_locations_company_id'), 'locations', ['company_id'], unique=False)
    op.create_index(op.f('ix_locations_id'), 'locations', ['id'], unique=False)
    op.create_table('product_varients',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('varient_id', sa.Integer(), nullable=False),
    sa.Column('sku', sa.String(length=255), nullable=True),
    sa.Column('varient_name', sa.String(length=255), nullable=False),
    sa.Column('attribute_details', sa.JSON(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_product_varients_company_id'), 'product_varients', ['company_id'], unique=False)
    op.create_index(op.f('ix_product_varients_id'), 'product_varients', ['id'], unique=False)
    op.create_index(op.f('ix_product_varients_varient_id'), 'product_varients', ['varient_id'], unique=True)
    op.create_table('vendors',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('vendor_id', sa.Integer(), nullable=True),
    sa.Column('vendor_name', sa.String(length=255), nullable=False),
    sa.Column('vendor_code', sa.String(length=100), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_vendors_company_id'), 'vendors', ['company_id'], unique=False)
    op.create_index(op.f('ix_vendors_id'), 'vendors', ['id'], unique=False)
    op.create_table('products',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('fk_product_category_id', sa.Integer(), nullable=True),
    sa.Column('product_variant_id', sa.Integer(), nullable=True),
    sa.Column('product_id', sa.Integer(), nullable=True),
    sa.Column('product_name', sa.String(length=500), nullable=False),
    sa.Column('short_name', sa.String(length=255), nullable=True),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('brand_name', sa.String(length=255), nullable=True),
    sa.Column('sku', sa.String(length=255), nullable=True),
    sa.Column('eligible_for_return', sa.Boolean(), nullable=True),
    sa.Column('display_on_pos', sa.Boolean(), nullable=True),
    sa.Column('display_on_online_store', sa.Boolean(), nullable=True),
    sa.Column('is_perishable', sa.Boolean(), nullable=True),
    sa.Column('image_path', sa.String(length=1000), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['fk_product_category_id'], ['categories.id'], ),
    sa.ForeignKeyConstraint(['product_variant_id'], ['product_varients.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_products_company_id'), 'products', ['company_id'], unique=False)
    op.create_index(op.f('ix_products_id'), 'products', ['id'], unique=False)
    op.create_table('purchase_orders',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('supplier_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.Column('status', sa.Enum('DRAFT', 'PENDING_APPROVAL', 'SENT', 'RECEIVED', 'RETURNED', 'CLOSED', name='purchaseorderstatus'), nullable=False),
    sa.Column('expected_delivery_date', sa.DateTime(timezone=True), nullable=True),
    sa.Column('ref_id', sa.Integer(), nullable=True),
    sa.Column('order_date', sa.DateTime(timezone=True), nullable=False),
    sa.Column('ref_number', sa.String(length=100), nullable=True),
    sa.Column('linked_ref_number', sa.String(length=100), nullable=True),
    sa.Column('linked_ref_datetime', sa.DateTime(timezone=True), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_purchase_orders_company_id'), 'purchase_orders', ['company_id'], unique=False)
    op.create_index(op.f('ix_purchase_orders_id'), 'purchase_orders', ['id'], unique=False)
    op.create_index(op.f('ix_purchase_orders_location_id'), 'purchase_orders', ['location_id'], unique=False)
    op.create_index(op.f('ix_purchase_orders_supplier_id'), 'purchase_orders', ['supplier_id'], unique=False)
    op.create_table('sales_orders',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.Column('sold_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('channel', sa.String(length=50), nullable=False),
    sa.Column('ref_id', sa.Integer(), nullable=True),
    sa.Column('order_date', sa.DateTime(timezone=True), nullable=False),
    sa.Column('ref_number', sa.String(length=100), nullable=True),
    sa.Column('linked_ref_number', sa.String(length=100), nullable=True),
    sa.Column('linked_ref_datetime', sa.DateTime(timezone=True), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_sales_orders_company_id'), 'sales_orders', ['company_id'], unique=False)
    op.create_index(op.f('ix_sales_orders_id'), 'sales_orders', ['id'], unique=False)
    op.create_index(op.f('ix_sales_orders_location_id'), 'sales_orders', ['location_id'], unique=False)
    op.create_table('daily_sales',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('product_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.Column('sale_date', sa.DateTime(timezone=True), nullable=False),
    sa.Column('quantity_sold', sa.Integer(), nullable=False),
    sa.Column('total_amount', sa.Float(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id'], ),
    sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_daily_sales_company_id'), 'daily_sales', ['company_id'], unique=False)
    op.create_index(op.f('ix_daily_sales_id'), 'daily_sales', ['id'], unique=False)
    op.create_index(op.f('ix_daily_sales_location_id'), 'daily_sales', ['location_id'], unique=False)
    op.create_index(op.f('ix_daily_sales_product_id'), 'daily_sales', ['product_id'], unique=False)
    op.create_index(op.f('ix_daily_sales_sale_date'), 'daily_sales', ['sale_date'], unique=False)
    op.create_table('demand_forecasts',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.Column('product_id', sa.Integer(), nullable=False),
    sa.Column('forecast_date', sa.Date(), nullable=False),
    sa.Column('target_date', sa.Date(), nullable=False),
    sa.Column('forecast_qty', sa.Float(), nullable=False),
    sa.Column('model_version', sa.String(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id'], ),
    sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_demand_forecasts_company_id'), 'demand_forecasts', ['company_id'], unique=False)
    op.create_index(op.f('ix_demand_forecasts_id'), 'demand_forecasts', ['id'], unique=False)
    op.create_index(op.f('ix_demand_forecasts_location_id'), 'demand_forecasts', ['location_id'], unique=False)
    op.create_index(op.f('ix_demand_forecasts_product_id'), 'demand_forecasts', ['product_id'], unique=False)
    op.create_table('inventory_batches',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('product_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.Column('batch_ref', sa.String(length=100), nullable=False),
    sa.Column('quantity_on_hand', sa.Integer(), nullable=False),
    sa.Column('expiry_date', sa.DateTime(timezone=True), nullable=True),
    sa.Column('received_date', sa.DateTime(timezone=True), nullable=False),
    sa.Column('status', sa.Enum('ACTIVE', 'SOLD_OUT', 'EXPIRED', 'DISPOSED', 'DONATED', name='inventorybatchstatus'), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id'], ),
    sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_inventory_batches_batch_ref'), 'inventory_batches', ['batch_ref'], unique=True)
    op.create_index(op.f('ix_inventory_batches_company_id'), 'inventory_batches', ['company_id'], unique=False)
    op.create_index(op.f('ix_inventory_batches_id'), 'inventory_batches', ['id'], unique=False)
    op.create_index(op.f('ix_inventory_batches_location_id'), 'inventory_batches', ['location_id'], unique=False)
    op.create_index(op.f('ix_inventory_batches_product_id'), 'inventory_batches', ['product_id'], unique=False)
    op.create_table('inventory_planning_snapshot',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('snapshot_date', sa.Date(), nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.Column('product_id', sa.Integer(), nullable=False),
    sa.Column('avg_daily_demand', sa.Float(), nullable=False),
    sa.Column('sigma_daily_demand', sa.Float(), nullable=False),
    sa.Column('lead_time_days', sa.Integer(), nullable=False),
    sa.Column('review_period_days', sa.Integer(), nullable=False),
    sa.Column('service_level_target', sa.Float(), nullable=False),
    sa.Column('current_safety_stock', sa.Float(), nullable=False),
    sa.Column('current_reorder_point', sa.Float(), nullable=False),
    sa.Column('forecast_avg_daily_demand_90d', sa.Float(), nullable=False),
    sa.Column('forecast_safety_stock_90d', sa.Float(), nullable=False),
    sa.Column('forecasted_reorder_point_90d', sa.Float(), nullable=False),
    sa.Column('on_hand_qty', sa.Float(), nullable=False),
    sa.Column('inbound_qty', sa.Float(), nullable=False),
    sa.Column('available_stock', sa.Float(), nullable=False),
    sa.Column('min_target', sa.Float(), nullable=False),
    sa.Column('max_target', sa.Float(), nullable=False),
    sa.Column('stock_status', sa.String(length=20), nullable=True),
    sa.Column('recommended_order_qty', sa.Float(), nullable=False),
    sa.Column('should_reorder', sa.Boolean(), nullable=False),
    sa.Column('days_of_cover', sa.Float(), nullable=True),
    sa.Column('days_until_stockout', sa.Float(), nullable=True),
    sa.Column('is_urgent', sa.Boolean(), nullable=False),
    sa.Column('urgency_score', sa.Float(), nullable=False),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id'], ),
    sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('snapshot_date', 'company_id', 'location_id', 'product_id', name='uq_planning_snapshot_per_day_sku_loc')
    )
    op.create_index(op.f('ix_inventory_planning_snapshot_company_id'), 'inventory_planning_snapshot', ['company_id'], unique=False)
    op.create_index(op.f('ix_inventory_planning_snapshot_id'), 'inventory_planning_snapshot', ['id'], unique=False)
    op.create_index(op.f('ix_inventory_planning_snapshot_location_id'), 'inventory_planning_snapshot', ['location_id'], unique=False)
    op.create_index(op.f('ix_inventory_planning_snapshot_product_id'), 'inventory_planning_snapshot', ['product_id'], unique=False)
    op.create_index(op.f('ix_inventory_planning_snapshot_snapshot_date'), 'inventory_planning_snapshot', ['snapshot_date'], unique=False)
    op.create_table('inventory_snapshot_daily',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('snapshot_date', sa.Date(), nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.Column('product_id', sa.Integer(), nullable=False),
    sa.Column('on_hand_qty', sa.Float(), nullable=False),
    sa.Column('inbound_qty', sa.Float(), nullable=False),
    sa.Column('outbound_qty', sa.Float(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id'], ),
    sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_inventory_snapshot_daily_company_id'), 'inventory_snapshot_daily', ['company_id'], unique=False)
    op.create_index(op.f('ix_inventory_snapshot_daily_id'), 'inventory_snapshot_daily', ['id'], unique=False)
    op.create_index(op.f('ix_inventory_snapshot_daily_location_id'), 'inventory_snapshot_daily', ['location_id'], unique=False)
    op.create_index(op.f('ix_inventory_snapshot_daily_product_id'), 'inventory_snapshot_daily', ['product_id'], unique=False)
    op.create_index(op.f('ix_inventory_snapshot_daily_snapshot_date'), 'inventory_snapshot_daily', ['snapshot_date'], unique=False)
    op.create_index('ix_snapshot_company_loc_prod_date', 'inventory_snapshot_daily', ['snapshot_date', 'company_id', 'location_id', 'product_id'], unique=True)
    op.create_table('product_locations',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('product_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id'], ),
    sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_product_locations_company_id'), 'product_locations', ['company_id'], unique=False)
    op.create_index(op.f('ix_product_locations_id'), 'product_locations', ['id'], unique=False)
    op.create_table('product_prices',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('product_price_id', sa.Integer(), nullable=True),
    sa.Column('product_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.Column('cost_price_per_unit', sa.Float(), nullable=True),
    sa.Column('markup_value', sa.Float(), nullable=True),
    sa.Column('margin_value', sa.Float(), nullable=True),
    sa.Column('retail_price_excl_tax', sa.Float(), nullable=True),
    sa.Column('compare_at_price', sa.Float(), nullable=True),
    sa.Column('markup_type_name', sa.String(length=50), nullable=True),
    sa.Column('margin_type_name', sa.String(length=50), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id'], ),
    sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_product_prices_company_id'), 'product_prices', ['company_id'], unique=False)
    op.create_index(op.f('ix_product_prices_id'), 'product_prices', ['id'], unique=False)
    op.create_index(op.f('ix_product_prices_location_id'), 'product_prices', ['location_id'], unique=False)
    op.create_index(op.f('ix_product_prices_product_id'), 'product_prices', ['product_id'], unique=False)
    op.create_table('product_vendors',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('product_id', sa.Integer(), nullable=False),
    sa.Column('vendor_id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
    sa.ForeignKeyConstraint(['vendor_id'], ['vendors.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_product_vendors_company_id'), 'product_vendors', ['company_id'], unique=False)
    op.create_index(op.f('ix_product_vendors_id'), 'product_vendors', ['id'], unique=False)
    op.create_table('purchase_order_lines',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('purchase_order_id', sa.Integer(), nullable=False),
    sa.Column('product_id', sa.Integer(), nullable=False),
    sa.Column('ordered_qty', sa.Integer(), nullable=False),
    sa.Column('received_qty', sa.Integer(), nullable=False),
    sa.Column('unit_cost', sa.Float(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
    sa.ForeignKeyConstraint(['purchase_order_id'], ['purchase_orders.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_purchase_order_lines_company_id'), 'purchase_order_lines', ['company_id'], unique=False)
    op.create_index(op.f('ix_purchase_order_lines_id'), 'purchase_order_lines', ['id'], unique=False)
    op.create_index(op.f('ix_purchase_order_lines_product_id'), 'purchase_order_lines', ['product_id'], unique=False)
    op.create_table('purchase_order_receive',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('supplier_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.Column('status', sa.Enum('DRAFT', 'PENDING_APPROVAL', 'SENT', 'RECEIVED', 'RETURNED', 'CLOSED', name='purchaseorderstatus'), nullable=False),
    sa.Column('expected_delivery_date', sa.DateTime(timezone=True), nullable=True),
    sa.Column('ref_id', sa.Integer(), nullable=True),
    sa.Column('purchase_order_id', sa.Integer(), nullable=True),
    sa.Column('order_date', sa.DateTime(timezone=True), nullable=False),
    sa.Column('ref_number', sa.String(length=100), nullable=True),
    sa.Column('linked_ref_number', sa.String(length=100), nullable=True),
    sa.Column('linked_ref_datetime', sa.DateTime(timezone=True), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id'], ),
    sa.ForeignKeyConstraint(['purchase_order_id'], ['purchase_orders.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_purchase_order_receive_company_id'), 'purchase_order_receive', ['company_id'], unique=False)
    op.create_index(op.f('ix_purchase_order_receive_id'), 'purchase_order_receive', ['id'], unique=False)
    op.create_index(op.f('ix_purchase_order_receive_location_id'), 'purchase_order_receive', ['location_id'], unique=False)
    op.create_index(op.f('ix_purchase_order_receive_supplier_id'), 'purchase_order_receive', ['supplier_id'], unique=False)
    op.create_table('reorder_policies',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.Column('product_id', sa.Integer(), nullable=False),
    sa.Column('lead_time_days', sa.Integer(), nullable=False),
    sa.Column('review_period_days', sa.Integer(), nullable=False),
    sa.Column('service_level_target', sa.Float(), nullable=False),
    sa.Column('min_order_qty', sa.Float(), nullable=False),
    sa.Column('supplier_id', sa.Integer(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id'], ),
    sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('company_id', 'location_id', 'product_id', name='uq_reorder_policy_company_loc_prod')
    )
    op.create_index(op.f('ix_reorder_policies_company_id'), 'reorder_policies', ['company_id'], unique=False)
    op.create_index(op.f('ix_reorder_policies_id'), 'reorder_policies', ['id'], unique=False)
    op.create_index(op.f('ix_reorder_policies_location_id'), 'reorder_policies', ['location_id'], unique=False)
    op.create_index(op.f('ix_reorder_policies_product_id'), 'reorder_policies', ['product_id'], unique=False)
    op.create_table('sales_order_lines',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('sales_order_id', sa.Integer(), nullable=False),
    sa.Column('product_id', sa.Integer(), nullable=False),
    sa.Column('quantity', sa.Integer(), nullable=False),
    sa.Column('unit_price', sa.Float(), nullable=False),
    sa.Column('promotion_id', sa.Integer(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
    sa.ForeignKeyConstraint(['promotion_id'], ['discounts.id'], ),
    sa.ForeignKeyConstraint(['sales_order_id'], ['sales_orders.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_sales_order_lines_company_id'), 'sales_order_lines', ['company_id'], unique=False)
    op.create_index(op.f('ix_sales_order_lines_id'), 'sales_order_lines', ['id'], unique=False)
    op.create_index(op.f('ix_sales_order_lines_product_id'), 'sales_order_lines', ['product_id'], unique=False)
    op.create_table('sales_return_orders',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.Column('sales_order_id', sa.Integer(), nullable=True),
    sa.Column('sold_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('channel', sa.String(length=50), nullable=False),
    sa.Column('ref_id', sa.Integer(), nullable=True),
    sa.Column('order_date', sa.DateTime(timezone=True), nullable=False),
    sa.Column('ref_number', sa.String(length=100), nullable=True),
    sa.Column('linked_ref_number', sa.String(length=100), nullable=True),
    sa.Column('linked_ref_datetime', sa.DateTime(timezone=True), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id'], ),
    sa.ForeignKeyConstraint(['sales_order_id'], ['sales_orders.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_sales_return_orders_company_id'), 'sales_return_orders', ['company_id'], unique=False)
    op.create_index(op.f('ix_sales_return_orders_id'), 'sales_return_orders', ['id'], unique=False)
    op.create_index(op.f('ix_sales_return_orders_location_id'), 'sales_return_orders', ['location_id'], unique=False)
    op.create_table('service_level_daily',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('date', sa.Date(), nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.Column('product_id', sa.Integer(), nullable=False),
    sa.Column('demand_qty', sa.Float(), nullable=False),
    sa.Column('fulfilled_qty', sa.Float(), nullable=False),
    sa.Column('lost_sales_qty', sa.Float(), nullable=False),
    sa.Column('service_level', sa.Float(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id'], ),
    sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_service_level_daily_company_id'), 'service_level_daily', ['company_id'], unique=False)
    op.create_index(op.f('ix_service_level_daily_date'), 'service_level_daily', ['date'], unique=False)
    op.create_index(op.f('ix_service_level_daily_id'), 'service_level_daily', ['id'], unique=False)
    op.create_index(op.f('ix_service_level_daily_location_id'), 'service_level_daily', ['location_id'], unique=False)
    op.create_index(op.f('ix_service_level_daily_product_id'), 'service_level_daily', ['product_id'], unique=False)
    op.create_index('ix_servicelvl_company_loc_prod_date', 'service_level_daily', ['date', 'company_id', 'location_id', 'product_id'], unique=True)
    op.create_table('slow_mover_snapshot',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('snapshot_date', sa.Date(), nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.Column('product_id', sa.Integer(), nullable=False),
    sa.Column('on_hand_qty', sa.Float(), nullable=False),
    sa.Column('total_sold_7d', sa.Float(), nullable=False),
    sa.Column('total_sold_30d', sa.Float(), nullable=False),
    sa.Column('total_sold_90d', sa.Float(), nullable=False),
    sa.Column('ads_7d', sa.Float(), nullable=False),
    sa.Column('ads_30d', sa.Float(), nullable=False),
    sa.Column('ads_90d', sa.Float(), nullable=False),
    sa.Column('doh_90d', sa.Float(), nullable=False),
    sa.Column('days_since_last_sale', sa.Integer(), nullable=False),
    sa.Column('is_slow_mover', sa.Boolean(), nullable=False),
    sa.Column('slow_mover_severity', sa.String(length=20), nullable=True),
    sa.Column('slow_mover_reason', sa.String(length=255), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id'], ),
    sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_slow_mover_snapshot_company_id'), 'slow_mover_snapshot', ['company_id'], unique=False)
    op.create_index(op.f('ix_slow_mover_snapshot_id'), 'slow_mover_snapshot', ['id'], unique=False)
    op.create_index(op.f('ix_slow_mover_snapshot_location_id'), 'slow_mover_snapshot', ['location_id'], unique=False)
    op.create_index(op.f('ix_slow_mover_snapshot_product_id'), 'slow_mover_snapshot', ['product_id'], unique=False)
    op.create_index(op.f('ix_slow_mover_snapshot_snapshot_date'), 'slow_mover_snapshot', ['snapshot_date'], unique=False)
    op.create_index('uq_slow_mover_snapshot_day_sku_loc', 'slow_mover_snapshot', ['snapshot_date', 'company_id', 'location_id', 'product_id'], unique=True)
    op.create_table('stockout_events',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.Column('product_id', sa.Integer(), nullable=False),
    sa.Column('date', sa.Date(), nullable=False),
    sa.Column('lost_sales_qty', sa.Float(), nullable=False),
    sa.Column('reason', sa.String(length=255), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id'], ),
    sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('ix_stockout_company_loc_prod_date', 'stockout_events', ['company_id', 'location_id', 'product_id', 'date'], unique=False)
    op.create_index(op.f('ix_stockout_events_company_id'), 'stockout_events', ['company_id'], unique=False)
    op.create_index(op.f('ix_stockout_events_date'), 'stockout_events', ['date'], unique=False)
    op.create_index(op.f('ix_stockout_events_id'), 'stockout_events', ['id'], unique=False)
    op.create_index(op.f('ix_stockout_events_location_id'), 'stockout_events', ['location_id'], unique=False)
    op.create_index(op.f('ix_stockout_events_product_id'), 'stockout_events', ['product_id'], unique=False)
    op.create_table('inventory_movements',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('product_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.Column('batch_id', sa.Integer(), nullable=True),
    sa.Column('movement_type', sa.Enum('SALE', 'RECEIPT', 'SALE_RETURN', 'PURCHASE_RETURN', 'ADJUSTMENT', 'TRANSFER_IN', 'TRANSFER_OUT', name='movementtype'), nullable=False),
    sa.Column('quantity_delta', sa.Integer(), nullable=False),
    sa.Column('reference', sa.String(length=100), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['batch_id'], ['inventory_batches.id'], ),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id'], ),
    sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_inventory_movements_company_id'), 'inventory_movements', ['company_id'], unique=False)
    op.create_index(op.f('ix_inventory_movements_id'), 'inventory_movements', ['id'], unique=False)
    op.create_index(op.f('ix_inventory_movements_location_id'), 'inventory_movements', ['location_id'], unique=False)
    op.create_index(op.f('ix_inventory_movements_product_id'), 'inventory_movements', ['product_id'], unique=False)
    op.create_table('purchase_order_receive_lines',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('purchase_order_receive_id', sa.Integer(), nullable=False),
    sa.Column('product_id', sa.Integer(), nullable=False),
    sa.Column('ordered_qty', sa.Integer(), nullable=False),
    sa.Column('received_qty', sa.Integer(), nullable=False),
    sa.Column('unit_cost', sa.Float(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
    sa.ForeignKeyConstraint(['purchase_order_receive_id'], ['purchase_order_receive.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_purchase_order_receive_lines_company_id'), 'purchase_order_receive_lines', ['company_id'], unique=False)
    op.create_index(op.f('ix_purchase_order_receive_lines_id'), 'purchase_order_receive_lines', ['id'], unique=False)
    op.create_index(op.f('ix_purchase_order_receive_lines_product_id'), 'purchase_order_receive_lines', ['product_id'], unique=False)
    op.create_table('purchase_order_return',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('supplier_id', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=False),
    sa.Column('status', sa.Enum('DRAFT', 'PENDING_APPROVAL', 'SENT', 'RECEIVED', 'RETURNED', 'CLOSED', name='purchaseorderstatus'), nullable=False),
    sa.Column('expected_delivery_date', sa.DateTime(timezone=True), nullable=True),
    sa.Column('ref_id', sa.Integer(), nullable=True),
    sa.Column('purchase_receive_order_id', sa.Integer(), nullable=True),
    sa.Column('order_date', sa.DateTime(timezone=True), nullable=False),
    sa.Column('ref_number', sa.String(length=100), nullable=True),
    sa.Column('linked_ref_number', sa.String(length=100), nullable=True),
    sa.Column('linked_ref_datetime', sa.DateTime(timezone=True), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id'], ),
    sa.ForeignKeyConstraint(['purchase_receive_order_id'], ['purchase_order_receive.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_purchase_order_return_company_id'), 'purchase_order_return', ['company_id'], unique=False)
    op.create_index(op.f('ix_purchase_order_return_id'), 'purchase_order_return', ['id'], unique=False)
    op.create_index(op.f('ix_purchase_order_return_location_id'), 'purchase_order_return', ['location_id'], unique=False)
    op.create_index(op.f('ix_purchase_order_return_supplier_id'), 'purchase_order_return', ['supplier_id'], unique=False)
    op.create_table('sales_return_order_lines',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('sales_return_order_id', sa.Integer(), nullable=False),
    sa.Column('product_id', sa.Integer(), nullable=False),
    sa.Column('quantity', sa.Integer(), nullable=False),
    sa.Column('unit_price', sa.Float(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
    sa.ForeignKeyConstraint(['sales_return_order_id'], ['sales_return_orders.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_sales_return_order_lines_company_id'), 'sales_return_order_lines', ['company_id'], unique=False)
    op.create_index(op.f('ix_sales_return_order_lines_id'), 'sales_return_order_lines', ['id'], unique=False)
    op.create_index(op.f('ix_sales_return_order_lines_product_id'), 'sales_return_order_lines', ['product_id'], unique=False)
    op.create_table('purchase_order_return_lines',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('purchase_order_return_id', sa.Integer(), nullable=False),
    sa.Column('product_id', sa.Integer(), nullable=False),
    sa.Column('ordered_qty', sa.Integer(), nullable=False),
    sa.Column('received_qty', sa.Integer(), nullable=False),
    sa.Column('unit_cost', sa.Float(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
    sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
    sa.ForeignKeyConstraint(['purchase_order_return_id'], ['purchase_order_return.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_purchase_order_return_lines_company_id'), 'purchase_order_return_lines', ['company_id'], unique=False)
    op.create_index(op.f('ix_purchase_order_return_lines_id'), 'purchase_order_return_lines', ['id'], unique=False)
    op.create_index(op.f('ix_purchase_order_return_lines_product_id'), 'purchase_order_return_lines', ['product_id'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_purchase_order_return_lines_product_id'), table_name='purchase_order_return_lines')
    op.drop_index(op.f('ix_purchase_order_return_lines_id'), table_name='purchase_order_return_lines')
    op.drop_index(op.f('ix_purchase_order_return_lines_company_id'), table_name='purchase_order_return_lines')
    op.drop_table('purchase_order_return_lines')
    op.drop_index(op.f('ix_sales_return_order_lines_product_id'), table_name='sales_return_order_lines')
    op.drop_index(op.f('ix_sales_return_order_lines_id'), table_name='sales_return_order_lines')
    op.drop_index(op.f('ix_sales_return_order_lines_company_id'), table_name='sales_return_order_lines')
    op.drop_table('sales_return_order_lines')
    op.drop_index(op.f('ix_purchase_order_return_supplier_id'), table_name='purchase_order_return')
    op.drop_index(op.f('ix_purchase_order_return_location_id'), table_name='purchase_order_return')
    op.drop_index(op.f('ix_purchase_order_return_id'), table_name='purchase_order_return')
    op.drop_index(op.f('ix_purchase_order_return_company_id'), table_name='purchase_order_return')
    op.drop_table('purchase_order_return')
    op.drop_index(op.f('ix_purchase_order_receive_lines_product_id'), table_name='purchase_order_receive_lines')
    op.drop_index(op.f('ix_purchase_order_receive_lines_id'), table_name='purchase_order_receive_lines')
    op.drop_index(op.f('ix_purchase_order_receive_lines_company_id'), table_name='purchase_order_receive_lines')
    op.drop_table('purchase_order_receive_lines')
    op.drop_index(op.f('ix_inventory_movements_product_id'), table_name='inventory_movements')
    op.drop_index(op.f('ix_inventory_movements_location_id'), table_name='inventory_movements')
    op.drop_index(op.f('ix_inventory_movements_id'), table_name='inventory_movements')
    op.drop_index(op.f('ix_inventory_movements_company_id'), table_name='inventory_movements')
    op.drop_table('inventory_movements')
    op.drop_index(op.f('ix_stockout_events_product_id'), table_name='stockout_events')
    op.drop_index(op.f('ix_stockout_events_location_id'), table_name='stockout_events')
    op.drop_index(op.f('ix_stockout_events_id'), table_name='stockout_events')
    op.drop_index(op.f('ix_stockout_events_date'), table_name='stockout_events')
    op.drop_index(op.f('ix_stockout_events_company_id'), table_name='stockout_events')
    op.drop_index('ix_stockout_company_loc_prod_date', table_name='stockout_events')
    op.drop_table('stockout_events')
    op.drop_index('uq_slow_mover_snapshot_day_sku_loc', table_name='slow_mover_snapshot')
    op.drop_index(op.f('ix_slow_mover_snapshot_snapshot_date'), table_name='slow_mover_snapshot')
    op.drop_index(op.f('ix_slow_mover_snapshot_product_id'), table_name='slow_mover_snapshot')
    op.drop_index(op.f('ix_slow_mover_snapshot_location_id'), table_name='slow_mover_snapshot')
    op.drop_index(op.f('ix_slow_mover_snapshot_id'), table_name='slow_mover_snapshot')
    op.drop_index(op.f('ix_slow_mover_snapshot_company_id'), table_name='slow_mover_snapshot')
    op.drop_table('slow_mover_snapshot')
    op.drop_index('ix_servicelvl_company_loc_prod_date', table_name='service_level_daily')
    op.drop_index(op.f('ix_service_level_daily_product_id'), table_name='service_level_daily')
    op.drop_index(op.f('ix_service_level_daily_location_id'), table_name='service_level_daily')
    op.drop_index(op.f('ix_service_level_daily_id'), table_name='service_level_daily')
    op.drop_index(op.f('ix_service_level_daily_date'), table_name='service_level_daily')
    op.drop_index(op.f('ix_service_level_daily_company_id'), table_name='service_level_daily')
    op.drop_table('service_level_daily')
    op.drop_index(op.f('ix_sales_return_orders_location_id'), table_name='sales_return_orders')
    op.drop_index(op.f('ix_sales_return_orders_id'), table_name='sales_return_orders')
    op.drop_index(op.f('ix_sales_return_orders_company_id'), table_name='sales_return_orders')
    op.drop_table('sales_return_orders')
    op.drop_index(op.f('ix_sales_order_lines_product_id'), table_name='sales_order_lines')
    op.drop_index(op.f('ix_sales_order_lines_id'), table_name='sales_order_lines')
    op.drop_index(op.f('ix_sales_order_lines_company_id'), table_name='sales_order_lines')
    op.drop_table('sales_order_lines')
    op.drop_index(op.f('ix_reorder_policies_product_id'), table_name='reorder_policies')
    op.drop_index(op.f('ix_reorder_policies_location_id'), table_name='reorder_policies')
    op.drop_index(op.f('ix_reorder_policies_id'), table_name='reorder_policies')
    op.drop_index(op.f('ix_reorder_policies_company_id'), table_name='reorder_policies')
    op.drop_table('reorder_policies')
    op.drop_index(op.f('ix_purchase_order_receive_supplier_id'), table_name='purchase_order_receive')
    op.drop_index(op.f('ix_purchase_order_receive_location_id'), table_name='purchase_order_receive')
    op.drop_index(op.f('ix_purchase_order_receive_id'), table_name='purchase_order_receive')
    op.drop_index(op.f('ix_purchase_order_receive_company_id'), table_name='purchase_order_receive')
    op.drop_table('purchase_order_receive')
    op.drop_index(op.f('ix_purchase_order_lines_product_id'), table_name='purchase_order_lines')
    op.drop_index(op.f('ix_purchase_order_lines_id'), table_name='purchase_order_lines')
    op.drop_index(op.f('ix_purchase_order_lines_company_id'), table_name='purchase_order_lines')
    op.drop_table('purchase_order_lines')
    op.drop_index(op.f('ix_product_vendors_id'), table_name='product_vendors')
    op.drop_index(op.f('ix_product_vendors_company_id'), table_name='product_vendors')
    op.drop_table('product_vendors')
    op.drop_index(op.f('ix_product_prices_product_id'), table_name='product_prices')
    op.drop_index(op.f('ix_product_prices_location_id'), table_name='product_prices')
    op.drop_index(op.f('ix_product_prices_id'), table_name='product_prices')
    op.drop_index(op.f('ix_product_prices_company_id'), table_name='product_prices')
    op.drop_table('product_prices')
    op.drop_index(op.f('ix_product_locations_id'), table_name='product_locations')
    op.drop_index(op.f('ix_product_locations_company_id'), table_name='product_locations')
    op.drop_table('product_locations')
    op.drop_index('ix_snapshot_company_loc_prod_date', table_name='inventory_snapshot_daily')
    op.drop_index(op.f('ix_inventory_snapshot_daily_snapshot_date'), table_name='inventory_snapshot_daily')
    op.drop_index(op.f('ix_inventory_snapshot_daily_product_id'), table_name='inventory_snapshot_daily')
    op.drop_index(op.f('ix_inventory_snapshot_daily_location_id'), table_name='inventory_snapshot_daily')
    op.drop_index(op.f('ix_inventory_snapshot_daily_id'), table_name='inventory_snapshot_daily')
    op.drop_index(op.f('ix_inventory_snapshot_daily_company_id'), table_name='inventory_snapshot_daily')
    op.drop_table('inventory_snapshot_daily')
    op.drop_index(op.f('ix_inventory_planning_snapshot_snapshot_date'), table_name='inventory_planning_snapshot')
    op.drop_index(op.f('ix_inventory_planning_snapshot_product_id'), table_name='inventory_planning_snapshot')
    op.drop_index(op.f('ix_inventory_planning_snapshot_location_id'), table_name='inventory_planning_snapshot')
    op.drop_index(op.f('ix_inventory_planning_snapshot_id'), table_name='inventory_planning_snapshot')
    op.drop_index(op.f('ix_inventory_planning_snapshot_company_id'), table_name='inventory_planning_snapshot')
    op.drop_table('inventory_planning_snapshot')
    op.drop_index(op.f('ix_inventory_batches_product_id'), table_name='inventory_batches')
    op.drop_index(op.f('ix_inventory_batches_location_id'), table_name='inventory_batches')
    op.drop_index(op.f('ix_inventory_batches_id'), table_name='inventory_batches')
    op.drop_index(op.f('ix_inventory_batches_company_id'), table_name='inventory_batches')
    op.drop_index(op.f('ix_inventory_batches_batch_ref'), table_name='inventory_batches')
    op.drop_table('inventory_batches')
    op.drop_index(op.f('ix_demand_forecasts_product_id'), table_name='demand_forecasts')
    op.drop_index(op.f('ix_demand_forecasts_location_id'), table_name='demand_forecasts')
    op.drop_index(op.f('ix_demand_forecasts_id'), table_name='demand_forecasts')
    op.drop_index(op.f('ix_demand_forecasts_company_id'), table_name='demand_forecasts')
    op.drop_table('demand_forecasts')
    op.drop_index(op.f('ix_daily_sales_sale_date'), table_name='daily_sales')
    op.drop_index(op.f('ix_daily_sales_product_id'), table_name='daily_sales')
    op.drop_index(op.f('ix_daily_sales_location_id'), table_name='daily_sales')
    op.drop_index(op.f('ix_daily_sales_id'), table_name='daily_sales')
    op.drop_index(op.f('ix_daily_sales_company_id'), table_name='daily_sales')
    op.drop_table('daily_sales')
    op.drop_index(op.f('ix_sales_orders_location_id'), table_name='sales_orders')
    op.drop_index(op.f('ix_sales_orders_id'), table_name='sales_orders')
    op.drop_index(op.f('ix_sales_orders_company_id'), table_name='sales_orders')
    op.drop_table('sales_orders')
    op.drop_index(op.f('ix_purchase_orders_supplier_id'), table_name='purchase_orders')
    op.drop_index(op.f('ix_purchase_orders_location_id'), table_name='purchase_orders')
    op.drop_index(op.f('ix_purchase_orders_id'), table_name='purchase_orders')
    op.drop_index(op.f('ix_purchase_orders_company_id'), table_name='purchase_orders')
    op.drop_table('purchase_orders')
    op.drop_index(op.f('ix_products_id'), table_name='products')
    op.drop_index(op.f('ix_products_company_id'), table_name='products')
    op.drop_table('products')
    op.drop_index(op.f('ix_vendors_id'), table_name='vendors')
    op.drop_index(op.f('ix_vendors_company_id'), table_name='vendors')
    op.drop_table('vendors')
    op.drop_index(op.f('ix_product_varients_varient_id'), table_name='product_varients')
    op.drop_index(op.f('ix_product_varients_id'), table_name='product_varients')
    op.drop_index(op.f('ix_product_varients_company_id'), table_name='product_varients')
    op.drop_table('product_varients')
    op.drop_index(op.f('ix_locations_id'), table_name='locations')
    op.drop_index(op.f('ix_locations_company_id'), table_name='locations')
    op.drop_table('locations')
    op.drop_index(op.f('ix_discounts_id'), table_name='discounts')
    op.drop_index(op.f('ix_discounts_discount_id'), table_name='discounts')
    op.drop_index(op.f('ix_discounts_company_id'), table_name='discounts')
    op.drop_table('discounts')
    op.drop_index(op.f('ix_categories_id'), table_name='categories')
    op.drop_index(op.f('ix_categories_company_id'), table_name='categories')
    op.drop_table('categories')
    op.drop_index(op.f('ix_companies_id'), table_name='companies')
    op.drop_index(op.f('ix_companies_company_id'), table_name='companies')
    op.drop_table('companies')
    # ### end Alembic commands ###
