feat: per-page SumUp models and migration (Phase 3)
- Migration: add market_place_id to cart_items, page_config_id to orders - Order model: add page_config_id FK and page_config relationship - CartItem model: add market_place_id FK and market_place relationship Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
55
alembic/versions/c3d4e5f6a7b8_add_page_tracking_to_orders.py
Normal file
55
alembic/versions/c3d4e5f6a7b8_add_page_tracking_to_orders.py
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
"""add page_config_id to orders, market_place_id to cart_items
|
||||||
|
|
||||||
|
Revision ID: c3d4e5f6a7b8
|
||||||
|
Revises: b2c3d4e5f6a7
|
||||||
|
Create Date: 2026-02-10
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
revision = 'c3d4e5f6a7b8'
|
||||||
|
down_revision = 'b2c3d4e5f6a7'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
# 1. Add market_place_id to cart_items
|
||||||
|
op.add_column(
|
||||||
|
'cart_items',
|
||||||
|
sa.Column('market_place_id', sa.Integer(), nullable=True),
|
||||||
|
)
|
||||||
|
op.create_foreign_key(
|
||||||
|
'fk_cart_items_market_place_id',
|
||||||
|
'cart_items',
|
||||||
|
'market_places',
|
||||||
|
['market_place_id'],
|
||||||
|
['id'],
|
||||||
|
ondelete='SET NULL',
|
||||||
|
)
|
||||||
|
op.create_index('ix_cart_items_market_place_id', 'cart_items', ['market_place_id'])
|
||||||
|
|
||||||
|
# 2. Add page_config_id to orders
|
||||||
|
op.add_column(
|
||||||
|
'orders',
|
||||||
|
sa.Column('page_config_id', sa.Integer(), nullable=True),
|
||||||
|
)
|
||||||
|
op.create_foreign_key(
|
||||||
|
'fk_orders_page_config_id',
|
||||||
|
'orders',
|
||||||
|
'page_configs',
|
||||||
|
['page_config_id'],
|
||||||
|
['id'],
|
||||||
|
ondelete='SET NULL',
|
||||||
|
)
|
||||||
|
op.create_index('ix_orders_page_config_id', 'orders', ['page_config_id'])
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
op.drop_index('ix_orders_page_config_id', table_name='orders')
|
||||||
|
op.drop_constraint('fk_orders_page_config_id', 'orders', type_='foreignkey')
|
||||||
|
op.drop_column('orders', 'page_config_id')
|
||||||
|
|
||||||
|
op.drop_index('ix_cart_items_market_place_id', table_name='cart_items')
|
||||||
|
op.drop_constraint('fk_cart_items_market_place_id', 'cart_items', type_='foreignkey')
|
||||||
|
op.drop_column('cart_items', 'market_place_id')
|
||||||
@@ -413,6 +413,12 @@ class CartItem(Base):
|
|||||||
nullable=False,
|
nullable=False,
|
||||||
server_default=func.now(),
|
server_default=func.now(),
|
||||||
)
|
)
|
||||||
|
market_place_id: Mapped[int | None] = mapped_column(
|
||||||
|
ForeignKey("market_places.id", ondelete="SET NULL"),
|
||||||
|
nullable=True,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
|
||||||
deleted_at: Mapped[datetime | None] = mapped_column(
|
deleted_at: Mapped[datetime | None] = mapped_column(
|
||||||
DateTime(timezone=True),
|
DateTime(timezone=True),
|
||||||
nullable=True,
|
nullable=True,
|
||||||
@@ -420,6 +426,10 @@ class CartItem(Base):
|
|||||||
|
|
||||||
# Relationships
|
# Relationships
|
||||||
|
|
||||||
|
market_place: Mapped["MarketPlace | None"] = relationship(
|
||||||
|
"MarketPlace",
|
||||||
|
foreign_keys=[market_place_id],
|
||||||
|
)
|
||||||
product: Mapped["Product"] = relationship(
|
product: Mapped["Product"] = relationship(
|
||||||
"Product",
|
"Product",
|
||||||
back_populates="cart_items",
|
back_populates="cart_items",
|
||||||
|
|||||||
@@ -17,6 +17,12 @@ class Order(Base):
|
|||||||
user_id: Mapped[Optional[int]] = mapped_column(ForeignKey("users.id"), nullable=True)
|
user_id: Mapped[Optional[int]] = mapped_column(ForeignKey("users.id"), nullable=True)
|
||||||
session_id: Mapped[Optional[str]] = mapped_column(String(64), index=True, nullable=True)
|
session_id: Mapped[Optional[str]] = mapped_column(String(64), index=True, nullable=True)
|
||||||
|
|
||||||
|
page_config_id: Mapped[Optional[int]] = mapped_column(
|
||||||
|
ForeignKey("page_configs.id", ondelete="SET NULL"),
|
||||||
|
nullable=True,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
|
||||||
status: Mapped[str] = mapped_column(
|
status: Mapped[str] = mapped_column(
|
||||||
String(32),
|
String(32),
|
||||||
nullable=False,
|
nullable=False,
|
||||||
@@ -68,6 +74,11 @@ class Order(Base):
|
|||||||
back_populates="order",
|
back_populates="order",
|
||||||
lazy="selectin",
|
lazy="selectin",
|
||||||
)
|
)
|
||||||
|
page_config: Mapped[Optional["PageConfig"]] = relationship(
|
||||||
|
"PageConfig",
|
||||||
|
foreign_keys=[page_config_id],
|
||||||
|
lazy="selectin",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class OrderItem(Base):
|
class OrderItem(Base):
|
||||||
|
|||||||
Reference in New Issue
Block a user