44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
"""add smart procurement settings to tenant settings
|
|
|
|
Revision ID: 20251025_procurement
|
|
Revises: 20251022_0000
|
|
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_procurement'
|
|
down_revision = '20251022_0000'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
"""Add smart procurement flags to existing procurement_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
|
|
procurement_settings = (procurement_settings::jsonb ||
|
|
'{"use_reorder_rules": true, "economic_rounding": true, "respect_storage_limits": true, "use_supplier_minimums": true, "optimize_price_tiers": true}'::jsonb)::json,
|
|
updated_at = now()
|
|
""")
|
|
|
|
|
|
def downgrade():
|
|
"""Remove smart procurement flags from procurement_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
|
|
procurement_settings = (procurement_settings::jsonb - 'use_reorder_rules' - 'economic_rounding' - 'respect_storage_limits' - 'use_supplier_minimums' - 'optimize_price_tiers')::json,
|
|
updated_at = now()
|
|
""")
|