Files
JQC_multi_tenant/migrations/versions/phase26_issue_vendor.py
T
2026-06-26 09:04:34 -04:00

51 lines
1.6 KiB
Python

"""phase26 — vendor/contractor columns on issues
Adds three nullable columns to the issues table:
vendor_name VARCHAR(100) — name of the external contractor or vendor
vendor_contact VARCHAR(200) — phone number or email for the vendor
vendor_notes TEXT — notes about what the vendor is handling
These columns are populated only when a third-party contractor is
assigned to resolve an issue, separate from the internal assigned_to staff user.
"""
import sqlalchemy as sa
from alembic import op
revision = 'phase26_issue_vendor'
down_revision = 'phase25_inspection_gps'
branch_labels = None
depends_on = None
def _col_exists(bind, table: str, column: str) -> bool:
result = bind.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 _col_exists(bind, 'issues', 'vendor_name'):
op.add_column('issues',
sa.Column('vendor_name', sa.String(100), nullable=True))
if not _col_exists(bind, 'issues', 'vendor_contact'):
op.add_column('issues',
sa.Column('vendor_contact', sa.String(200), nullable=True))
if not _col_exists(bind, 'issues', 'vendor_notes'):
op.add_column('issues',
sa.Column('vendor_notes', sa.Text, nullable=True))
def downgrade():
op.drop_column('issues', 'vendor_notes')
op.drop_column('issues', 'vendor_contact')
op.drop_column('issues', 'vendor_name')