Files
rose-ash/cart/alembic/versions/0003_add_container_relations.py
giles 1f3d98ecc1 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>
2026-02-26 17:49:30 +00:00

41 lines
1.5 KiB
Python

"""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")