42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
"""phase22 — add is_customer_visible to issue_comments
|
|
|
|
Staff comments default to hidden from customers (is_customer_visible=FALSE).
|
|
Staff can tick a checkbox to share a comment with the customer.
|
|
Customer comments are always visible (is_customer_visible=TRUE, set at write time).
|
|
"""
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision = 'phase22_comment_visibility'
|
|
down_revision = 'phase21_performance_indexes'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def _column_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 = :table "
|
|
" AND column_name = :column"
|
|
), {'table': table, 'column': column})
|
|
return result.scalar() > 0
|
|
|
|
|
|
def upgrade():
|
|
bind = op.get_bind()
|
|
if not _column_exists(bind, 'issue_comments', 'is_customer_visible'):
|
|
op.execute(sa.text(
|
|
'ALTER TABLE issue_comments '
|
|
'ADD COLUMN is_customer_visible BOOLEAN NOT NULL DEFAULT FALSE'
|
|
))
|
|
|
|
|
|
def downgrade():
|
|
bind = op.get_bind()
|
|
if _column_exists(bind, 'issue_comments', 'is_customer_visible'):
|
|
op.execute(sa.text(
|
|
'ALTER TABLE issue_comments DROP COLUMN is_customer_visible'
|
|
))
|