Files
docqube_backend/alembic/versions/i001_dual_bucket_storage.py
T
2026-09-08 11:00:05 +05:30

57 lines
1.6 KiB
Python

"""Replace b2_bucket_name with b2_quarantine_bucket and b2_clean_bucket
Revision ID: i001_dual_bucket_storage
Revises: 9557c7307575
Create Date: 2026-03-17 08:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'i001_dual_bucket_storage'
down_revision = '9557c7307575'
branch_labels = None
depends_on = None
def upgrade() -> None:
# 1. Add the two new bucket columns (nullable at first)
op.add_column(
'tenant_storage_configs',
sa.Column('b2_quarantine_bucket', sa.String(255), nullable=True)
)
op.add_column(
'tenant_storage_configs',
sa.Column('b2_clean_bucket', sa.String(255), nullable=True)
)
# 2. Migrate existing b2_bucket_name to quarantine (best-effort)
op.execute("""
UPDATE tenant_storage_configs
SET b2_quarantine_bucket = b2_bucket_name
WHERE b2_bucket_name IS NOT NULL
""")
# 3. Drop the old column
op.drop_column('tenant_storage_configs', 'b2_bucket_name')
def downgrade() -> None:
# 1. Restore the old column
op.add_column(
'tenant_storage_configs',
sa.Column('b2_bucket_name', sa.String(255), nullable=True)
)
# 2. Restore data from quarantine bucket (best-effort)
op.execute("""
UPDATE tenant_storage_configs
SET b2_bucket_name = b2_quarantine_bucket
WHERE b2_quarantine_bucket IS NOT NULL
""")
# 3. Drop the new columns
op.drop_column('tenant_storage_configs', 'b2_clean_bucket')
op.drop_column('tenant_storage_configs', 'b2_quarantine_bucket')