Move container_relations to cart service for cross-service ownership

container_relations is a generic parent/child graph used by blog
(menu_nodes), market (marketplaces), and events (calendars). Move it
to cart as shared infrastructure. All services now call cart actions
(attach-child/detach-child) instead of querying the table directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-26 17:49:30 +00:00
parent dd52417241
commit 1f3d98ecc1
7 changed files with 154 additions and 14 deletions

View File

@@ -5,10 +5,11 @@ MODELS = [
"shared.models.market", # CartItem lives here
"shared.models.order",
"shared.models.page_config",
"shared.models.container_relation",
]
TABLES = frozenset({
"cart_items", "orders", "order_items", "page_configs",
"cart_items", "orders", "order_items", "page_configs", "container_relations",
})
run_alembic(context.config, MODELS, TABLES)

View File

@@ -0,0 +1,40 @@
"""Add container_relations table to cart DB.
Generic parent/child graph for inter-service container relationships
(page→market, page→calendar, page→menu_node, etc.).
Revision ID: cart_0003
Revises: cart_0002
Create Date: 2026-02-26
"""
import sqlalchemy as sa
from alembic import op
revision = "cart_0003"
down_revision = "cart_0002"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.create_table(
"container_relations",
sa.Column("id", sa.Integer, primary_key=True, autoincrement=True),
sa.Column("parent_type", sa.String(32), nullable=False),
sa.Column("parent_id", sa.Integer, nullable=False),
sa.Column("child_type", sa.String(32), nullable=False),
sa.Column("child_id", sa.Integer, nullable=False),
sa.Column("sort_order", sa.Integer, nullable=False, server_default="0"),
sa.Column("label", sa.String(255), nullable=True),
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
sa.Column("deleted_at", sa.DateTime(timezone=True), nullable=True),
sa.UniqueConstraint("parent_type", "parent_id", "child_type", "child_id",
name="uq_container_relations_parent_child"),
)
op.create_index("ix_container_relations_parent", "container_relations", ["parent_type", "parent_id"])
op.create_index("ix_container_relations_child", "container_relations", ["child_type", "child_id"])
def downgrade() -> None:
op.drop_table("container_relations")