| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- """Initial migration - create all tables
- Revision ID: 7aa055089aea
- Revises:
- Create Date: 2026-01-02 00:45:00.414032
- """
- from alembic import op
- import sqlalchemy as sa
- # revision identifiers, used by Alembic.
- revision = '7aa055089aea'
- down_revision = None
- branch_labels = None
- depends_on = None
- def upgrade():
- # ### commands auto generated by Alembic - please adjust! ###
- op.create_table('aws_credentials',
- sa.Column('id', sa.Integer(), nullable=False),
- sa.Column('name', sa.String(length=100), nullable=False),
- sa.Column('credential_type', sa.Enum('assume_role', 'access_key', name='credential_type'), nullable=False),
- sa.Column('account_id', sa.String(length=12), nullable=False),
- sa.Column('role_arn', sa.String(length=255), nullable=True),
- sa.Column('external_id', sa.String(length=255), nullable=True),
- sa.Column('access_key_id', sa.String(length=255), nullable=True),
- sa.Column('secret_access_key_encrypted', sa.Text(), nullable=True),
- sa.Column('created_at', sa.DateTime(), nullable=True),
- sa.Column('is_active', sa.Boolean(), nullable=True),
- sa.PrimaryKeyConstraint('id')
- )
- with op.batch_alter_table('aws_credentials', schema=None) as batch_op:
- batch_op.create_index(batch_op.f('ix_aws_credentials_account_id'), ['account_id'], unique=False)
- op.create_table('base_assume_role_config',
- sa.Column('id', sa.Integer(), nullable=False),
- sa.Column('access_key_id', sa.String(length=255), nullable=False),
- sa.Column('secret_access_key_encrypted', sa.Text(), nullable=False),
- sa.Column('updated_at', sa.DateTime(), nullable=True),
- sa.PrimaryKeyConstraint('id')
- )
- op.create_table('users',
- sa.Column('id', sa.Integer(), nullable=False),
- sa.Column('username', sa.String(length=50), nullable=False),
- sa.Column('email', sa.String(length=100), nullable=False),
- sa.Column('password_hash', sa.String(length=255), nullable=False),
- sa.Column('role', sa.Enum('admin', 'power_user', 'user', name='user_role'), nullable=True),
- sa.Column('created_at', sa.DateTime(), nullable=True),
- sa.Column('is_active', sa.Boolean(), nullable=True),
- sa.PrimaryKeyConstraint('id')
- )
- with op.batch_alter_table('users', schema=None) as batch_op:
- batch_op.create_index(batch_op.f('ix_users_email'), ['email'], unique=True)
- batch_op.create_index(batch_op.f('ix_users_username'), ['username'], unique=True)
- op.create_table('tasks',
- sa.Column('id', sa.Integer(), nullable=False),
- sa.Column('name', sa.String(length=200), nullable=False),
- sa.Column('status', sa.Enum('pending', 'running', 'completed', 'failed', name='task_status'), nullable=True),
- sa.Column('progress', sa.Integer(), nullable=True),
- sa.Column('created_by', sa.Integer(), nullable=False),
- sa.Column('created_at', sa.DateTime(), nullable=True),
- sa.Column('started_at', sa.DateTime(), nullable=True),
- sa.Column('completed_at', sa.DateTime(), nullable=True),
- sa.Column('celery_task_id', sa.String(length=100), nullable=True),
- sa.Column('credential_ids', sa.Text(), nullable=True),
- sa.Column('regions', sa.Text(), nullable=True),
- sa.Column('project_metadata', sa.Text(), nullable=True),
- sa.ForeignKeyConstraint(['created_by'], ['users.id'], ),
- sa.PrimaryKeyConstraint('id')
- )
- with op.batch_alter_table('tasks', schema=None) as batch_op:
- batch_op.create_index(batch_op.f('ix_tasks_celery_task_id'), ['celery_task_id'], unique=False)
- batch_op.create_index(batch_op.f('ix_tasks_created_at'), ['created_at'], unique=False)
- batch_op.create_index(batch_op.f('ix_tasks_status'), ['status'], unique=False)
- op.create_table('user_credentials',
- sa.Column('id', sa.Integer(), nullable=False),
- sa.Column('user_id', sa.Integer(), nullable=False),
- sa.Column('credential_id', sa.Integer(), nullable=False),
- sa.Column('assigned_at', sa.DateTime(), nullable=True),
- sa.ForeignKeyConstraint(['credential_id'], ['aws_credentials.id'], ),
- sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
- sa.PrimaryKeyConstraint('id'),
- sa.UniqueConstraint('user_id', 'credential_id', name='unique_user_credential')
- )
- op.create_table('reports',
- sa.Column('id', sa.Integer(), nullable=False),
- sa.Column('task_id', sa.Integer(), nullable=False),
- sa.Column('file_name', sa.String(length=255), nullable=False),
- sa.Column('file_path', sa.String(length=500), nullable=False),
- sa.Column('file_size', sa.Integer(), nullable=True),
- sa.Column('created_at', sa.DateTime(), nullable=True),
- sa.ForeignKeyConstraint(['task_id'], ['tasks.id'], ),
- sa.PrimaryKeyConstraint('id'),
- sa.UniqueConstraint('task_id')
- )
- with op.batch_alter_table('reports', schema=None) as batch_op:
- batch_op.create_index(batch_op.f('ix_reports_created_at'), ['created_at'], unique=False)
- op.create_table('task_logs',
- sa.Column('id', sa.Integer(), nullable=False),
- sa.Column('task_id', sa.Integer(), nullable=False),
- sa.Column('level', sa.Enum('info', 'warning', 'error', name='log_level'), nullable=True),
- sa.Column('message', sa.Text(), nullable=False),
- sa.Column('details', sa.Text(), nullable=True),
- sa.Column('created_at', sa.DateTime(), nullable=True),
- sa.ForeignKeyConstraint(['task_id'], ['tasks.id'], ),
- sa.PrimaryKeyConstraint('id')
- )
- with op.batch_alter_table('task_logs', schema=None) as batch_op:
- batch_op.create_index(batch_op.f('ix_task_logs_created_at'), ['created_at'], unique=False)
- batch_op.create_index(batch_op.f('ix_task_logs_task_id'), ['task_id'], unique=False)
- # ### end Alembic commands ###
- def downgrade():
- # ### commands auto generated by Alembic - please adjust! ###
- with op.batch_alter_table('task_logs', schema=None) as batch_op:
- batch_op.drop_index(batch_op.f('ix_task_logs_task_id'))
- batch_op.drop_index(batch_op.f('ix_task_logs_created_at'))
- op.drop_table('task_logs')
- with op.batch_alter_table('reports', schema=None) as batch_op:
- batch_op.drop_index(batch_op.f('ix_reports_created_at'))
- op.drop_table('reports')
- op.drop_table('user_credentials')
- with op.batch_alter_table('tasks', schema=None) as batch_op:
- batch_op.drop_index(batch_op.f('ix_tasks_status'))
- batch_op.drop_index(batch_op.f('ix_tasks_created_at'))
- batch_op.drop_index(batch_op.f('ix_tasks_celery_task_id'))
- op.drop_table('tasks')
- with op.batch_alter_table('users', schema=None) as batch_op:
- batch_op.drop_index(batch_op.f('ix_users_username'))
- batch_op.drop_index(batch_op.f('ix_users_email'))
- op.drop_table('users')
- op.drop_table('base_assume_role_config')
- with op.batch_alter_table('aws_credentials', schema=None) as batch_op:
- batch_op.drop_index(batch_op.f('ix_aws_credentials_account_id'))
- op.drop_table('aws_credentials')
- # ### end Alembic commands ###
|