Files
orion/app/modules/cart/migrations/versions/cart_001_initial.py
Samir Boulahtit c3d26e9aa4 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>
2026-02-08 11:51:37 +01:00

36 lines
1.3 KiB
Python

"""cart initial - cart items
Revision ID: cart_001
Revises: inventory_001
Create Date: 2026-02-07
"""
from alembic import op
import sqlalchemy as sa
revision = "cart_001"
down_revision = "inventory_001"
branch_labels = None
depends_on = None
def upgrade() -> None:
# --- cart_items ---
op.create_table(
"cart_items",
sa.Column("id", sa.Integer(), primary_key=True, index=True),
sa.Column("store_id", sa.Integer(), sa.ForeignKey("stores.id"), nullable=False),
sa.Column("product_id", sa.Integer(), sa.ForeignKey("products.id"), nullable=False),
sa.Column("session_id", sa.String(255), nullable=False, index=True),
sa.Column("quantity", sa.Integer(), nullable=False, server_default="1"),
sa.Column("price_at_add_cents", sa.Integer(), nullable=False),
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", "session_id", "product_id", name="uq_cart_item"),
)
op.create_index("idx_cart_session", "cart_items", ["store_id", "session_id"])
op.create_index("idx_cart_created", "cart_items", ["created_at"])
def downgrade() -> None:
op.drop_table("cart_items")