"""Persist Application.default_knowledge_space_ids, previously accepted by the control-plane API and echoed back in the same create/read response but silently discarded on every subsequent round-trip -- the `applications` table had no column or table for it at all. A join table (mirroring `grants`'s own application<->space composite-FK shape) rather than a JSON array column: this is a real many-to-many relationship the domain already models as a `frozenset[UUID]`, and every other application<->space relationship in this schema (`grants`) already uses a join table, not a JSON column. """ from __future__ import annotations import sqlalchemy as sa from alembic import op revision = "0015_application_default_spaces" down_revision = "0014_document_space" branch_labels = None depends_on = None def upgrade() -> None: op.create_table( "application_default_spaces", sa.Column("application_id", sa.Uuid(), primary_key=True), sa.Column("workspace_id", sa.Uuid(), nullable=False), sa.Column("knowledge_space_id", sa.Uuid(), primary_key=True), sa.ForeignKeyConstraint( ["application_id", "workspace_id"], ["control.applications.id", "control.applications.workspace_id"], ondelete="CASCADE", ), sa.ForeignKeyConstraint( ["knowledge_space_id", "workspace_id"], ["control.spaces.id", "control.spaces.workspace_id"], ondelete="CASCADE", ), schema="control", ) def downgrade() -> None: op.drop_table("application_default_spaces", schema="control")