"""add merged_x / merged_y to table_combination

Persists the user-edited position of the "merged" rectangle that visually
represents an active combination on the floor-plan editor. Previously the
position lived only in client-side `$state` (`mergedComboPositions` in
`tables/+page.svelte`), so dragging the combo rectangle felt like it saved
but the coordinates were discarded on page reload or any layout invalidate.

Both columns are nullable: `NULL` means "no user-edited position yet — fall
back to the centroid of the combo's component tables", which matches the
prior client-side default and keeps existing rows valid without a backfill.

Revision ID: 0031_table_combination_merged_position
Revises: 0030_rls_via_pg_session_jwt
Create Date: 2026-05-26 21:00:00.000000
"""

from collections.abc import Sequence

import sqlalchemy as sa

from alembic import op

revision: str = "0031_table_combination_merged_position"
down_revision: str | None = "0030_rls_via_pg_session_jwt"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    op.add_column(
        "table_combination",
        sa.Column("merged_x", sa.Float(), nullable=True),
    )
    op.add_column(
        "table_combination",
        sa.Column("merged_y", sa.Float(), nullable=True),
    )


def downgrade() -> None:
    op.drop_column("table_combination", "merged_y")
    op.drop_column("table_combination", "merged_x")
