|
| 1 | +"""Add foreign key to each object table to link to api id row |
| 2 | +
|
| 3 | +Revision ID: 9afeb4e61715 |
| 4 | +Revises: 39e8a680df30 |
| 5 | +Create Date: 2023-05-08 12:24:21.494334 |
| 6 | +
|
| 7 | +""" |
| 8 | +from alembic import op |
| 9 | +import sqlalchemy as sa |
| 10 | +from sqlalchemy.dialects import mysql |
| 11 | + |
| 12 | +# revision identifiers, used by Alembic. |
| 13 | +revision = '9afeb4e61715' |
| 14 | +down_revision = '39e8a680df30' |
| 15 | +branch_labels = None |
| 16 | +depends_on = None |
| 17 | + |
| 18 | + |
| 19 | +def upgrade() -> None: |
| 20 | + # ### commands auto generated by Alembic - please adjust! ### |
| 21 | + op.add_column('agent', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 22 | + op.create_foreign_key(None, 'agent', 'api_id', ['api_id_fk'], ['id']) |
| 23 | + op.add_column('agent_pool', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 24 | + op.create_foreign_key(None, 'agent_pool', 'api_id', ['api_id_fk'], ['id']) |
| 25 | + op.add_column('agent_token', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 26 | + op.create_foreign_key(None, 'agent_token', 'api_id', ['api_id_fk'], ['id']) |
| 27 | + op.drop_index('_api_id_suffix_index', table_name='api_id') |
| 28 | + op.drop_index('_object_class_object_id_in', table_name='api_id') |
| 29 | + op.drop_index('_object_class_object_id_uc', table_name='api_id') |
| 30 | + op.drop_column('api_id', 'object_class') |
| 31 | + op.drop_column('api_id', 'object_id') |
| 32 | + op.add_column('apply', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 33 | + op.create_foreign_key(None, 'apply', 'api_id', ['api_id_fk'], ['id']) |
| 34 | + op.add_column('audit_event', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 35 | + op.create_foreign_key(None, 'audit_event', 'api_id', ['api_id_fk'], ['id']) |
| 36 | + op.add_column('authorised_repo', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 37 | + op.create_foreign_key(None, 'authorised_repo', 'api_id', ['api_id_fk'], ['id']) |
| 38 | + op.add_column('blob', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 39 | + op.create_foreign_key(None, 'blob', 'api_id', ['api_id_fk'], ['id']) |
| 40 | + op.add_column('configuration_version', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 41 | + op.create_foreign_key(None, 'configuration_version', 'api_id', ['api_id_fk'], ['id']) |
| 42 | + op.add_column('environment', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 43 | + op.create_foreign_key(None, 'environment', 'api_id', ['api_id_fk'], ['id']) |
| 44 | + op.add_column('github_app_oauth_token', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 45 | + op.create_foreign_key(None, 'github_app_oauth_token', 'api_id', ['api_id_fk'], ['id']) |
| 46 | + op.add_column('lifecycle', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 47 | + op.create_foreign_key(None, 'lifecycle', 'api_id', ['api_id_fk'], ['id']) |
| 48 | + op.add_column('oauth_client', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 49 | + op.create_foreign_key(None, 'oauth_client', 'api_id', ['api_id_fk'], ['id']) |
| 50 | + op.add_column('oauth_token', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 51 | + op.create_foreign_key(None, 'oauth_token', 'api_id', ['api_id_fk'], ['id']) |
| 52 | + op.add_column('organisation', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 53 | + op.create_foreign_key(None, 'organisation', 'api_id', ['api_id_fk'], ['id']) |
| 54 | + op.add_column('plan', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 55 | + op.create_foreign_key(None, 'plan', 'api_id', ['api_id_fk'], ['id']) |
| 56 | + op.add_column('project', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 57 | + op.create_foreign_key(None, 'project', 'api_id', ['api_id_fk'], ['id']) |
| 58 | + op.add_column('run', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 59 | + op.create_foreign_key(None, 'run', 'api_id', ['api_id_fk'], ['id']) |
| 60 | + op.add_column('run_queue', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 61 | + op.create_foreign_key(None, 'run_queue', 'api_id', ['api_id_fk'], ['id']) |
| 62 | + op.add_column('state_version', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 63 | + op.create_foreign_key(None, 'state_version', 'api_id', ['api_id_fk'], ['id']) |
| 64 | + op.add_column('tag', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 65 | + op.create_foreign_key(None, 'tag', 'api_id', ['api_id_fk'], ['id']) |
| 66 | + op.add_column('task', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 67 | + op.create_foreign_key(None, 'task', 'api_id', ['api_id_fk'], ['id']) |
| 68 | + op.add_column('task_result', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 69 | + op.create_foreign_key(None, 'task_result', 'api_id', ['api_id_fk'], ['id']) |
| 70 | + op.add_column('task_stage', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 71 | + op.create_foreign_key(None, 'task_stage', 'api_id', ['api_id_fk'], ['id']) |
| 72 | + op.add_column('team', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 73 | + op.create_foreign_key(None, 'team', 'api_id', ['api_id_fk'], ['id']) |
| 74 | + op.add_column('team_workspace_access', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 75 | + op.create_foreign_key(None, 'team_workspace_access', 'api_id', ['api_id_fk'], ['id']) |
| 76 | + op.add_column('user', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 77 | + op.create_foreign_key(None, 'user', 'api_id', ['api_id_fk'], ['id']) |
| 78 | + op.add_column('user_token', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 79 | + op.create_foreign_key(None, 'user_token', 'api_id', ['api_id_fk'], ['id']) |
| 80 | + op.add_column('workspace', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 81 | + op.create_foreign_key(None, 'workspace', 'api_id', ['api_id_fk'], ['id']) |
| 82 | + op.add_column('workspace_task', sa.Column('api_id_fk', sa.Integer(), nullable=True)) |
| 83 | + op.create_foreign_key(None, 'workspace_task', 'api_id', ['api_id_fk'], ['id']) |
| 84 | + # ### end Alembic commands ### |
| 85 | + |
| 86 | + |
| 87 | +def downgrade() -> None: |
| 88 | + # ### commands auto generated by Alembic - please adjust! ### |
| 89 | + op.drop_constraint(None, 'workspace_task', type_='foreignkey') |
| 90 | + op.drop_column('workspace_task', 'api_id_fk') |
| 91 | + op.drop_constraint(None, 'workspace', type_='foreignkey') |
| 92 | + op.drop_column('workspace', 'api_id_fk') |
| 93 | + op.drop_constraint(None, 'user_token', type_='foreignkey') |
| 94 | + op.drop_column('user_token', 'api_id_fk') |
| 95 | + op.drop_constraint(None, 'user', type_='foreignkey') |
| 96 | + op.drop_column('user', 'api_id_fk') |
| 97 | + op.drop_constraint(None, 'team_workspace_access', type_='foreignkey') |
| 98 | + op.drop_column('team_workspace_access', 'api_id_fk') |
| 99 | + op.drop_constraint(None, 'team', type_='foreignkey') |
| 100 | + op.drop_column('team', 'api_id_fk') |
| 101 | + op.drop_constraint(None, 'task_stage', type_='foreignkey') |
| 102 | + op.drop_column('task_stage', 'api_id_fk') |
| 103 | + op.drop_constraint(None, 'task_result', type_='foreignkey') |
| 104 | + op.drop_column('task_result', 'api_id_fk') |
| 105 | + op.drop_constraint(None, 'task', type_='foreignkey') |
| 106 | + op.drop_column('task', 'api_id_fk') |
| 107 | + op.drop_constraint(None, 'tag', type_='foreignkey') |
| 108 | + op.drop_column('tag', 'api_id_fk') |
| 109 | + op.drop_constraint(None, 'state_version', type_='foreignkey') |
| 110 | + op.drop_column('state_version', 'api_id_fk') |
| 111 | + op.drop_constraint(None, 'run_queue', type_='foreignkey') |
| 112 | + op.drop_column('run_queue', 'api_id_fk') |
| 113 | + op.drop_constraint(None, 'run', type_='foreignkey') |
| 114 | + op.drop_column('run', 'api_id_fk') |
| 115 | + op.drop_constraint(None, 'project', type_='foreignkey') |
| 116 | + op.drop_column('project', 'api_id_fk') |
| 117 | + op.drop_constraint(None, 'plan', type_='foreignkey') |
| 118 | + op.drop_column('plan', 'api_id_fk') |
| 119 | + op.drop_constraint(None, 'organisation', type_='foreignkey') |
| 120 | + op.drop_column('organisation', 'api_id_fk') |
| 121 | + op.drop_constraint(None, 'oauth_token', type_='foreignkey') |
| 122 | + op.drop_column('oauth_token', 'api_id_fk') |
| 123 | + op.drop_constraint(None, 'oauth_client', type_='foreignkey') |
| 124 | + op.drop_column('oauth_client', 'api_id_fk') |
| 125 | + op.drop_constraint(None, 'lifecycle', type_='foreignkey') |
| 126 | + op.drop_column('lifecycle', 'api_id_fk') |
| 127 | + op.drop_constraint(None, 'github_app_oauth_token', type_='foreignkey') |
| 128 | + op.drop_column('github_app_oauth_token', 'api_id_fk') |
| 129 | + op.drop_constraint(None, 'environment', type_='foreignkey') |
| 130 | + op.drop_column('environment', 'api_id_fk') |
| 131 | + op.drop_constraint(None, 'configuration_version', type_='foreignkey') |
| 132 | + op.drop_column('configuration_version', 'api_id_fk') |
| 133 | + op.drop_constraint(None, 'blob', type_='foreignkey') |
| 134 | + op.drop_column('blob', 'api_id_fk') |
| 135 | + op.drop_constraint(None, 'authorised_repo', type_='foreignkey') |
| 136 | + op.drop_column('authorised_repo', 'api_id_fk') |
| 137 | + op.drop_constraint(None, 'audit_event', type_='foreignkey') |
| 138 | + op.drop_column('audit_event', 'api_id_fk') |
| 139 | + op.drop_constraint(None, 'apply', type_='foreignkey') |
| 140 | + op.drop_column('apply', 'api_id_fk') |
| 141 | + op.add_column('api_id', sa.Column('object_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True)) |
| 142 | + op.add_column('api_id', sa.Column('object_class', mysql.VARCHAR(length=128), nullable=True)) |
| 143 | + op.create_index('_object_class_object_id_uc', 'api_id', ['object_class', 'object_id'], unique=False) |
| 144 | + op.create_index('_object_class_object_id_in', 'api_id', ['object_class', 'object_id'], unique=False) |
| 145 | + op.create_index('_api_id_suffix_index', 'api_id', ['api_id_suffix'], unique=False) |
| 146 | + op.drop_constraint(None, 'agent_token', type_='foreignkey') |
| 147 | + op.drop_column('agent_token', 'api_id_fk') |
| 148 | + op.drop_constraint(None, 'agent_pool', type_='foreignkey') |
| 149 | + op.drop_column('agent_pool', 'api_id_fk') |
| 150 | + op.drop_constraint(None, 'agent', type_='foreignkey') |
| 151 | + op.drop_column('agent', 'api_id_fk') |
| 152 | + # ### end Alembic commands ### |
0 commit comments