004_add_task_source_field.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. """Add source and scan_data_path fields to Task model
  2. Revision ID: 004_add_task_source_field
  3. Revises: 003_add_session_token
  4. Create Date: 2026-01-24
  5. This migration adds support for CloudShell Scanner upload functionality:
  6. - source: Indicates whether the task was created via 'credential' scan or 'upload'
  7. - scan_data_path: Path to the uploaded JSON file for upload-based tasks
  8. """
  9. from alembic import op
  10. import sqlalchemy as sa
  11. # revision identifiers, used by Alembic.
  12. revision = '004_add_task_source_field'
  13. down_revision = '003_add_session_token'
  14. branch_labels = None
  15. depends_on = None
  16. def upgrade():
  17. """Add source and scan_data_path columns to tasks table"""
  18. # Add source column with default value 'credential'
  19. op.add_column('tasks',
  20. sa.Column('source', sa.String(20), nullable=True, server_default='credential'))
  21. # Add scan_data_path column for storing uploaded JSON file path
  22. op.add_column('tasks',
  23. sa.Column('scan_data_path', sa.String(500), nullable=True))
  24. # Update existing rows to have 'credential' as source
  25. op.execute("UPDATE tasks SET source = 'credential' WHERE source IS NULL")
  26. def downgrade():
  27. """Remove source and scan_data_path columns from tasks table"""
  28. op.drop_column('tasks', 'scan_data_path')
  29. op.drop_column('tasks', 'source')