Jul 8 - Implement issue assignment separation
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
"""phase35 — issue handler_type + facility-staff handler fields
|
||||
|
||||
Separates WHO handles an issue into three categories:
|
||||
internal — one of our staff (existing assigned_to User)
|
||||
facility — the facility's own staff (new free-text facility_handler_* fields)
|
||||
vendor — an external contractor (existing vendor_* fields, phase26)
|
||||
|
||||
`assigned_to` remains the internal follow-up owner in all cases.
|
||||
|
||||
Backfills existing rows that already have a vendor_name to handler_type='vendor'.
|
||||
Uses INFORMATION_SCHEMA column-existence checks — safe to re-run.
|
||||
"""
|
||||
|
||||
revision = 'phase35_issue_handler'
|
||||
down_revision = 'phase34_facility_qr'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def _column_exists(conn, table, column):
|
||||
result = 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})
|
||||
return result.scalar() > 0
|
||||
|
||||
|
||||
def upgrade():
|
||||
bind = op.get_bind()
|
||||
|
||||
if not _column_exists(bind, 'issues', 'handler_type'):
|
||||
op.execute(sa.text(
|
||||
"ALTER TABLE issues ADD COLUMN handler_type "
|
||||
"ENUM('internal','facility','vendor') NOT NULL DEFAULT 'internal'"
|
||||
))
|
||||
|
||||
if not _column_exists(bind, 'issues', 'facility_handler_name'):
|
||||
op.execute(sa.text(
|
||||
"ALTER TABLE issues ADD COLUMN facility_handler_name VARCHAR(100) NULL"
|
||||
))
|
||||
if not _column_exists(bind, 'issues', 'facility_handler_contact'):
|
||||
op.execute(sa.text(
|
||||
"ALTER TABLE issues ADD COLUMN facility_handler_contact VARCHAR(200) NULL"
|
||||
))
|
||||
if not _column_exists(bind, 'issues', 'facility_handler_notes'):
|
||||
op.execute(sa.text(
|
||||
"ALTER TABLE issues ADD COLUMN facility_handler_notes TEXT NULL"
|
||||
))
|
||||
|
||||
# Backfill: rows already carrying a vendor become handler_type='vendor'
|
||||
# so existing contractor assignments keep their meaning.
|
||||
op.execute(sa.text(
|
||||
"UPDATE issues SET handler_type = 'vendor' "
|
||||
"WHERE handler_type = 'internal' "
|
||||
"AND vendor_name IS NOT NULL AND TRIM(vendor_name) <> ''"
|
||||
))
|
||||
|
||||
|
||||
def downgrade():
|
||||
bind = op.get_bind()
|
||||
for col in ('facility_handler_notes', 'facility_handler_contact',
|
||||
'facility_handler_name', 'handler_type'):
|
||||
if _column_exists(bind, 'issues', col):
|
||||
op.execute(sa.text(f"ALTER TABLE issues DROP COLUMN {col}"))
|
||||
Reference in New Issue
Block a user