fix(scheduling): repair missing participation gateway column
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
"""v0.1.10 scheduling participation gateway schema repair
|
||||
|
||||
Revision ID: be8f4d2c1a70
|
||||
Revises: ad7e3c9b2f10
|
||||
Create Date: 2026-07-22 00:00:00.000000
|
||||
|
||||
Some development databases were stamped at ``ad7e3c9b2f10`` before the
|
||||
``scheduling_participants.participation_gateway`` column was present. A
|
||||
forward repair is required because Alembic correctly does not replay an
|
||||
already-recorded revision. The column is nullable, so adding it preserves all
|
||||
existing participant rows without inventing gateway ownership for legacy
|
||||
invitations.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision = "be8f4d2c1a70"
|
||||
down_revision = "ad7e3c9b2f10"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def _require_compatible_column(column: dict[str, object]) -> None:
|
||||
column_type = column["type"]
|
||||
if (
|
||||
not column.get("nullable")
|
||||
or not isinstance(column_type, sa.String)
|
||||
or column_type.length != 40
|
||||
):
|
||||
raise RuntimeError(
|
||||
"Cannot adopt scheduling_participants.participation_gateway "
|
||||
"because its schema is unexpected"
|
||||
)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
inspector = sa.inspect(op.get_bind())
|
||||
if "scheduling_participants" not in inspector.get_table_names():
|
||||
raise RuntimeError(
|
||||
"Cannot repair Scheduling participation gateways because "
|
||||
"scheduling_participants is missing"
|
||||
)
|
||||
|
||||
columns = {
|
||||
item["name"]: item
|
||||
for item in inspector.get_columns("scheduling_participants")
|
||||
}
|
||||
existing = columns.get("participation_gateway")
|
||||
if existing is not None:
|
||||
_require_compatible_column(existing)
|
||||
return
|
||||
|
||||
op.add_column(
|
||||
"scheduling_participants",
|
||||
sa.Column("participation_gateway", sa.String(length=40), nullable=True),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ad7e3c9b2f10 already owns this column in the canonical schema. The repair
|
||||
# revision must therefore not remove it when returning to that revision.
|
||||
pass
|
||||
Reference in New Issue
Block a user