50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
"""phase47 — scheduled inspection receipt acknowledgement
|
|
|
|
Adds to `scheduled_inspections`:
|
|
|
|
acknowledged_at DATETIME NULL
|
|
|
|
When the assigned inspector confirms they have received/seen a scheduled
|
|
inspection request. NULL = awaiting confirmation. Reset to NULL by the edit
|
|
route when the schedule is reassigned to a different inspector (once per
|
|
assignment, not per occurrence). The acknowledger is always the assigned
|
|
inspector, so no separate acknowledged_by column is stored.
|
|
|
|
No backfill: legacy rows keep NULL and render as "awaiting confirmation", which
|
|
is the correct initial state for an assignment nobody has confirmed yet.
|
|
|
|
Uses INFORMATION_SCHEMA check — safe to re-run.
|
|
"""
|
|
|
|
revision = 'phase47_sched_acknowledged'
|
|
down_revision = 'phase46_followup_req_by'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
def _column_exists(conn, table, column):
|
|
return conn.execute(sa.text(
|
|
"SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS "
|
|
"WHERE TABLE_SCHEMA = DATABASE() "
|
|
"AND TABLE_NAME = :t AND COLUMN_NAME = :c"
|
|
), {"t": table, "c": column}).scalar() > 0
|
|
|
|
|
|
def upgrade():
|
|
bind = op.get_bind()
|
|
if not _column_exists(bind, 'scheduled_inspections', 'acknowledged_at'):
|
|
op.execute(sa.text(
|
|
"ALTER TABLE scheduled_inspections ADD COLUMN acknowledged_at DATETIME NULL"
|
|
))
|
|
|
|
|
|
def downgrade():
|
|
bind = op.get_bind()
|
|
if _column_exists(bind, 'scheduled_inspections', 'acknowledged_at'):
|
|
op.execute(sa.text(
|
|
"ALTER TABLE scheduled_inspections DROP COLUMN acknowledged_at"
|
|
))
|