Replace hardcoded homepage featured route groups with a fully managed dynamic system: - add database models RouteSection and RouteSectionProduct for storing route groups and their associated products - create Alembic migration 0004_route_sections for the new tables - extend SiteConfigPatchIn schema with subtitle and productIds fields - refactor shared site_config utility to load dynamic route sections instead of fixed groups - implement admin CRUD API with validation for duplicate/conflicting product associations - update public and admin API documentation to reflect the new system - add default route section seed data and comprehensive test coverage
55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
"""Add route section configuration.
|
|
|
|
Revision ID: 0004_route_sections
|
|
Revises: 0003_campaign_display_fields
|
|
Create Date: 2026-07-02
|
|
"""
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy import inspect
|
|
|
|
|
|
revision = "0004_route_sections"
|
|
down_revision = "0003_campaign_display_fields"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
bind = op.get_bind()
|
|
existing_tables = set(inspect(bind).get_table_names())
|
|
|
|
if "RouteSection" not in existing_tables:
|
|
op.create_table(
|
|
"RouteSection",
|
|
sa.Column("id", sa.String(), nullable=False),
|
|
sa.Column("title", sa.String(), nullable=False),
|
|
sa.Column("subtitle", sa.Text(), nullable=True),
|
|
sa.Column("sortOrder", sa.Integer(), nullable=False, server_default="0"),
|
|
sa.Column("isActive", sa.Boolean(), nullable=False, server_default=sa.true()),
|
|
sa.Column("createdAt", sa.DateTime(), nullable=False),
|
|
sa.Column("updatedAt", sa.DateTime(), nullable=False),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
|
|
if "RouteSectionProduct" not in existing_tables:
|
|
op.create_table(
|
|
"RouteSectionProduct",
|
|
sa.Column("sectionId", sa.String(), nullable=False),
|
|
sa.Column("productId", sa.String(), nullable=False),
|
|
sa.Column("sortOrder", sa.Integer(), nullable=False, server_default="0"),
|
|
sa.ForeignKeyConstraint(["productId"], ["Product.id"], ondelete="CASCADE"),
|
|
sa.ForeignKeyConstraint(["sectionId"], ["RouteSection.id"], ondelete="CASCADE"),
|
|
sa.PrimaryKeyConstraint("sectionId", "productId"),
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
bind = op.get_bind()
|
|
existing_tables = set(inspect(bind).get_table_names())
|
|
if "RouteSectionProduct" in existing_tables:
|
|
op.drop_table("RouteSectionProduct")
|
|
if "RouteSection" in existing_tables:
|
|
op.drop_table("RouteSection")
|