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:
2026-02-08 11:51:37 +01:00
parent dad02695f6
commit c3d26e9aa4
111 changed files with 2285 additions and 11723 deletions

View File

@@ -58,6 +58,7 @@ catalog_module = ModuleDefinition(
version="1.0.0",
is_self_contained=True,
requires=["inventory"],
migrations_path="migrations",
features=[
"product_catalog", # Core product catalog functionality
"product_search", # Search and filtering

View File

@@ -0,0 +1 @@
"""Module migrations."""

View File

@@ -0,0 +1 @@
"""Module migrations."""

View File

@@ -0,0 +1,97 @@
"""catalog initial - products, translations, product media
Revision ID: catalog_001
Revises: cms_001
Create Date: 2026-02-07
"""
from alembic import op
import sqlalchemy as sa
revision = "catalog_001"
down_revision = "cms_001"
branch_labels = None
depends_on = None
def upgrade() -> None:
# --- products ---
op.create_table(
"products",
sa.Column("id", sa.Integer(), primary_key=True, index=True),
sa.Column("store_id", sa.Integer(), sa.ForeignKey("stores.id"), nullable=False),
sa.Column("marketplace_product_id", sa.Integer(), sa.ForeignKey("marketplace_products.id"), nullable=True),
sa.Column("store_sku", sa.String(), nullable=True, index=True),
sa.Column("gtin", sa.String(50), nullable=True, index=True),
sa.Column("gtin_type", sa.String(20), nullable=True),
sa.Column("price_cents", sa.Integer(), nullable=True),
sa.Column("sale_price_cents", sa.Integer(), nullable=True),
sa.Column("currency", sa.String(3), nullable=True, server_default="EUR"),
sa.Column("brand", sa.String(), nullable=True),
sa.Column("condition", sa.String(), nullable=True),
sa.Column("availability", sa.String(), nullable=True),
sa.Column("primary_image_url", sa.String(), nullable=True),
sa.Column("additional_images", sa.JSON(), nullable=True),
sa.Column("download_url", sa.String(), nullable=True),
sa.Column("license_type", sa.String(50), nullable=True),
sa.Column("tax_rate_percent", sa.Integer(), nullable=False, server_default="17"),
sa.Column("supplier", sa.String(50), nullable=True),
sa.Column("supplier_product_id", sa.String(), nullable=True),
sa.Column("cost_cents", sa.Integer(), nullable=True),
sa.Column("margin_percent_x100", sa.Integer(), nullable=True),
sa.Column("is_digital", sa.Boolean(), nullable=True, server_default="false", index=True),
sa.Column("product_type", sa.String(20), nullable=True, server_default="physical"),
sa.Column("is_featured", sa.Boolean(), nullable=True, server_default="false"),
sa.Column("is_active", sa.Boolean(), nullable=True, server_default="true"),
sa.Column("display_order", sa.Integer(), nullable=True, server_default="0"),
sa.Column("min_quantity", sa.Integer(), nullable=True, server_default="1"),
sa.Column("max_quantity", sa.Integer(), nullable=True),
sa.Column("fulfillment_email_template", sa.String(), nullable=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("store_id", "marketplace_product_id", name="uq_store_marketplace_product"),
)
op.create_index("idx_product_store_active", "products", ["store_id", "is_active"])
op.create_index("idx_product_store_featured", "products", ["store_id", "is_featured"])
op.create_index("idx_product_store_sku", "products", ["store_id", "store_sku"])
op.create_index("idx_product_supplier", "products", ["supplier", "supplier_product_id"])
# --- product_translations ---
op.create_table(
"product_translations",
sa.Column("id", sa.Integer(), primary_key=True, index=True),
sa.Column("product_id", sa.Integer(), sa.ForeignKey("products.id", ondelete="CASCADE"), nullable=False),
sa.Column("language", sa.String(5), nullable=False),
sa.Column("title", sa.String(), nullable=True),
sa.Column("description", sa.Text(), nullable=True),
sa.Column("short_description", sa.String(500), nullable=True),
sa.Column("meta_title", sa.String(70), nullable=True),
sa.Column("meta_description", sa.String(160), nullable=True),
sa.Column("url_slug", sa.String(255), nullable=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", "language", name="uq_product_translation"),
)
op.create_index("idx_pt_product_id", "product_translations", ["product_id"])
op.create_index("idx_pt_product_language", "product_translations", ["product_id", "language"])
# --- product_media ---
op.create_table(
"product_media",
sa.Column("id", sa.Integer(), primary_key=True, index=True),
sa.Column("product_id", sa.Integer(), sa.ForeignKey("products.id", ondelete="CASCADE"), nullable=False),
sa.Column("media_id", sa.Integer(), sa.ForeignKey("media_files.id", ondelete="CASCADE"), nullable=False),
sa.Column("usage_type", sa.String(50), nullable=False, server_default="gallery"),
sa.Column("display_order", sa.Integer(), nullable=True, server_default="0"),
sa.Column("variant_id", sa.Integer(), nullable=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", "media_id", "usage_type", name="uq_product_media_usage"),
)
op.create_index("idx_product_media_product", "product_media", ["product_id"])
op.create_index("idx_product_media_media", "product_media", ["media_id"])
def downgrade() -> None:
op.drop_table("product_media")
op.drop_table("product_translations")
op.drop_table("products")

View File

@@ -121,11 +121,11 @@ class Product(Base, TimestampMixin):
# === CONSTRAINTS & INDEXES ===
__table_args__ = (
UniqueConstraint(
"store_id", "marketplace_product_id", name="uq_vendor_marketplace_product"
"store_id", "marketplace_product_id", name="uq_store_marketplace_product"
),
Index("idx_product_vendor_active", "store_id", "is_active"),
Index("idx_product_vendor_featured", "store_id", "is_featured"),
Index("idx_product_vendor_sku", "store_id", "store_sku"),
Index("idx_product_store_active", "store_id", "is_active"),
Index("idx_product_store_featured", "store_id", "is_featured"),
Index("idx_product_store_sku", "store_id", "store_sku"),
Index("idx_product_supplier", "supplier", "supplier_product_id"),
)