002_make_account_id_nullable.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. """Make account_id nullable for access_key credentials
  2. Revision ID: 002
  3. Revises: 001
  4. Create Date: 2026-01-02 00:00:00.000000
  5. """
  6. from alembic import op
  7. import sqlalchemy as sa
  8. # revision identifiers
  9. revision = '002'
  10. down_revision = '001'
  11. branch_labels = None
  12. depends_on = None
  13. def upgrade():
  14. """Make account_id column nullable for access_key type credentials"""
  15. # Make account_id nullable
  16. with op.batch_alter_table('aws_credentials', schema=None) as batch_op:
  17. batch_op.alter_column('account_id',
  18. existing_type=sa.String(12),
  19. nullable=True)
  20. def downgrade():
  21. """Revert account_id column to not nullable"""
  22. # First, update any NULL account_id values to a placeholder
  23. op.execute("UPDATE aws_credentials SET account_id = '000000000000' WHERE account_id IS NULL")
  24. # Make account_id not nullable again
  25. with op.batch_alter_table('aws_credentials', schema=None) as batch_op:
  26. batch_op.alter_column('account_id',
  27. existing_type=sa.String(12),
  28. nullable=False)