Files
ss-tools/backend/alembic/versions/t1u2v3w4x5y6_drop_orphaned_connection_configs.py
busya e7d33ce4c8 chore(db): drop orphaned dataset-review and connection_configs tables
Remove dead schema left behind by removed features:
- dataset-review family (dataset_review_sessions, dataset_profiles, and
  related children) from c3ad0afc — its non-cascading FKs broke environment
  deletion with ForeignKeyViolation
- connection_configs from 74e64622

Both are unreachable from the app (no models register them).
2026-08-11 10:55:52 +03:00

60 lines
2.2 KiB
Python

# #region Alembic.DropOrphanedConnectionConfigs [C:2] [TYPE Module] [SEMANTICS alembic,connections,cleanup]
# @ingroup Alembic
# @BRIEF Drop the orphaned connection_configs table left by the removed connections feature.
# @LAYER Database
# @RELATION DEPENDS_ON -> [Models.Connection] (removed in 36643024)
# @RATIONALE The connection configuration feature was removed from the codebase
# (commit 36643024 "refactor(connections): remove ConnectionConfig, migrate
# mapper to SQL Lab"), but the connection_configs table was never dropped. It
# is unreachable from the app (no model registers it, so init_db()/create_all()
# will not recreate it) and carries no foreign keys, so it is inert — but it is
# dead schema and should be removed for cleanliness.
# @INVARIANT Only drops connection_configs; guarded by a table-exists check so it
# is a no-op on databases that already removed the table manually.
# @REJECTED Keeping the table — dead schema that shadows the removed feature.
"""drop orphaned connection_configs table
Revision ID: t1u2v3w4x5y6
Revises: t0u1v2w3x4y5
Create Date: 2026-08-11 10:55:00.000000
"""
from collections.abc import Sequence
from sqlalchemy import inspect
from alembic import op
revision: str = "t1u2v3w4x5y6"
down_revision: str | Sequence[str] | None = "t0u1v2w3x4y5"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
ORPHANED_TABLE = "connection_configs"
def _table_exists(table: str) -> bool:
"""Return whether a table currently exists in the database."""
return inspect(op.get_bind()).has_table(table)
def upgrade() -> None:
"""Drop the orphaned connection_configs table."""
if _table_exists(ORPHANED_TABLE):
op.drop_table(ORPHANED_TABLE)
def downgrade() -> None:
"""Restore connection_configs is intentionally unsupported.
The feature that created this table was removed (commit 36643024), so the
original DDL no longer exists in the codebase. Recreating it here would
invent schema.
"""
raise NotImplementedError(
"Dropping the orphaned connection_configs table is not reversible: the "
"feature that created it was removed (commit 36643024)."
)
# #endregion Alembic.DropOrphanedConnectionConfigs