refactor(migrations): squash 75 migrations into 12 per-module initial migrations
The old migration chain was broken (downgrade path through vendor->merchant rename made rollbacks impossible). This squashes everything into fresh per-module migrations with zero schema drift, verified by autogenerate. Changes: - Replace 75 accumulated migrations with 12 per-module initial migrations (core, billing, catalog, marketplace, cms, customers, orders, inventory, cart, messaging, loyalty, dev_tools) in a linear chain - Fix make db-reset to use SQL DROP SCHEMA instead of alembic downgrade base - Enable migration autodiscovery for all modules (migrations_path in definitions) - Rewrite alembic/env.py to import all 75 model tables across 13 modules - Fix AdminNotification import (was incorrectly from tenancy, now from messaging) - Update squash_migrations.py to handle all module migration directories Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -145,6 +145,7 @@ inventory_module = ModuleDefinition(
|
||||
models_path="app.modules.inventory.models",
|
||||
schemas_path="app.modules.inventory.schemas",
|
||||
exceptions_path="app.modules.inventory.exceptions",
|
||||
migrations_path="migrations",
|
||||
# Metrics provider for dashboard statistics
|
||||
metrics_provider=_get_metrics_provider,
|
||||
# Feature provider for feature flags
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
"""inventory initial - inventory, inventory transactions
|
||||
|
||||
Revision ID: inventory_001
|
||||
Revises: orders_001
|
||||
Create Date: 2026-02-07
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision = "inventory_001"
|
||||
down_revision = "orders_001"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# --- inventory ---
|
||||
op.create_table(
|
||||
"inventory",
|
||||
sa.Column("id", sa.Integer(), primary_key=True, index=True),
|
||||
sa.Column("product_id", sa.Integer(), sa.ForeignKey("products.id"), nullable=False, index=True),
|
||||
sa.Column("store_id", sa.Integer(), sa.ForeignKey("stores.id"), nullable=False, index=True),
|
||||
sa.Column("warehouse", sa.String(), nullable=False, server_default="strassen", index=True),
|
||||
sa.Column("bin_location", sa.String(), nullable=False, index=True),
|
||||
sa.Column("location", sa.String(), nullable=True, index=True),
|
||||
sa.Column("quantity", sa.Integer(), nullable=False, server_default="0"),
|
||||
sa.Column("reserved_quantity", sa.Integer(), nullable=True, server_default="0"),
|
||||
sa.Column("gtin", sa.String(), nullable=True, index=True),
|
||||
sa.Column("created_at", sa.DateTime(), server_default=sa.func.now(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), server_default=sa.func.now(), nullable=False),
|
||||
sa.UniqueConstraint("product_id", "warehouse", "bin_location", name="uq_inventory_product_warehouse_bin"),
|
||||
)
|
||||
op.create_index("idx_inventory_store_product", "inventory", ["store_id", "product_id"])
|
||||
op.create_index("idx_inventory_warehouse_bin", "inventory", ["warehouse", "bin_location"])
|
||||
|
||||
# --- inventory_transactions ---
|
||||
# Create the enum type for transaction_type
|
||||
transaction_type_enum = sa.Enum(
|
||||
"reserve", "fulfill", "release", "adjust", "set", "import", "return",
|
||||
name="transactiontype",
|
||||
)
|
||||
op.create_table(
|
||||
"inventory_transactions",
|
||||
sa.Column("id", sa.Integer(), primary_key=True, index=True),
|
||||
sa.Column("store_id", sa.Integer(), sa.ForeignKey("stores.id"), nullable=False, index=True),
|
||||
sa.Column("product_id", sa.Integer(), sa.ForeignKey("products.id"), nullable=False, index=True),
|
||||
sa.Column("inventory_id", sa.Integer(), sa.ForeignKey("inventory.id"), nullable=True, index=True),
|
||||
sa.Column("transaction_type", transaction_type_enum, nullable=False, index=True),
|
||||
sa.Column("quantity_change", sa.Integer(), nullable=False),
|
||||
sa.Column("quantity_after", sa.Integer(), nullable=False),
|
||||
sa.Column("reserved_after", sa.Integer(), nullable=False, server_default="0"),
|
||||
sa.Column("location", sa.String(), nullable=True),
|
||||
sa.Column("warehouse", sa.String(), nullable=True),
|
||||
sa.Column("order_id", sa.Integer(), sa.ForeignKey("orders.id"), nullable=True, index=True),
|
||||
sa.Column("order_number", sa.String(), nullable=True),
|
||||
sa.Column("reason", sa.Text(), nullable=True),
|
||||
sa.Column("created_by", sa.String(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False, index=True),
|
||||
)
|
||||
op.create_index("idx_inv_tx_store_product", "inventory_transactions", ["store_id", "product_id"])
|
||||
op.create_index("idx_inv_tx_store_created", "inventory_transactions", ["store_id", "created_at"])
|
||||
op.create_index("idx_inv_tx_order", "inventory_transactions", ["order_id"])
|
||||
op.create_index("idx_inv_tx_type_created", "inventory_transactions", ["transaction_type", "created_at"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table("inventory_transactions")
|
||||
op.drop_table("inventory")
|
||||
sa.Enum(name="transactiontype").drop(op.get_bind(), checkfirst=True)
|
||||
Reference in New Issue
Block a user