004_add_cloudshell_scanner_fields.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. """Add CloudShell Scanner fields to tasks table
  2. Revision ID: 004_cloudshell_scanner
  3. Revises: 003_add_session_token_to_base_role
  4. Create Date: 2026-01-23
  5. This migration adds the source and scan_data_path fields to the tasks table
  6. to support the CloudShell Scanner feature.
  7. Requirements:
  8. - 4.3: Task model needs source field to distinguish between credential and upload tasks
  9. """
  10. from alembic import op
  11. import sqlalchemy as sa
  12. # revision identifiers, used by Alembic.
  13. revision = '004_cloudshell_scanner'
  14. down_revision = '003_add_session_token_to_base_role'
  15. branch_labels = None
  16. depends_on = None
  17. def upgrade():
  18. """Add source and scan_data_path columns to tasks table."""
  19. # Add source column with default value 'credential'
  20. with op.batch_alter_table('tasks', schema=None) as batch_op:
  21. batch_op.add_column(
  22. sa.Column('source', sa.String(length=20), nullable=True, default='credential')
  23. )
  24. batch_op.add_column(
  25. sa.Column('scan_data_path', sa.String(length=500), nullable=True)
  26. )
  27. # Update existing rows to have 'credential' as source
  28. op.execute("UPDATE tasks SET source = 'credential' WHERE source IS NULL")
  29. def downgrade():
  30. """Remove source and scan_data_path columns from tasks table."""
  31. with op.batch_alter_table('tasks', schema=None) as batch_op:
  32. batch_op.drop_column('scan_data_path')
  33. batch_op.drop_column('source')