"""add supplier approval workflow settings to tenant settings Revision ID: 20251025_supplier_approval Revises: 20251025_procurement Create Date: 2025-10-25 """ from alembic import op import sqlalchemy as sa from sqlalchemy.dialects import postgresql import json # revision identifiers, used by Alembic. revision = '20251025_supplier_approval' down_revision = '20251025_procurement' branch_labels = None depends_on = None def upgrade(): """Add supplier approval workflow settings to existing supplier_settings""" # Use a single SQL statement to update all rows at once # This avoids cursor lock issues and is more efficient # Note: Cast to jsonb for merge operator, then back to json op.execute(""" UPDATE tenant_settings SET supplier_settings = (supplier_settings::jsonb || '{"require_supplier_approval": true, "auto_approve_for_admin_owner": true, "approval_required_roles": ["member", "viewer"]}'::jsonb)::json, updated_at = now() """) def downgrade(): """Remove supplier approval workflow settings from supplier_settings""" # Use a single SQL statement to remove the keys from all rows # Note: Cast to jsonb for operator, then back to json op.execute(""" UPDATE tenant_settings SET supplier_settings = (supplier_settings::jsonb - 'require_supplier_approval' - 'auto_approve_for_admin_owner' - 'approval_required_roles')::json, updated_at = now() """)