Coverage for /builds/BuildGrid/buildgrid/buildgrid/server/sql/alembic/versions/b57c30a687fa_add_client_identities_table.py: 76.47%
17 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-10-04 17:48 +0000
« prev ^ index » next coverage.py v7.4.1, created at 2024-10-04 17:48 +0000
1# Copyright (C) 2020 Bloomberg LP
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# <http://www.apache.org/licenses/LICENSE-2.0>
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
15"""Add client_identities table
17Revision ID: b57c30a687fa
18Revises: 53e8b8b5bed6
19Create Date: 2023-04-11 14:22:08.511246
21"""
22import sqlalchemy as sa
23from alembic import op
25# revision identifiers, used by Alembic.
26revision = "b57c30a687fa"
27down_revision = "53e8b8b5bed6"
28branch_labels = None
29depends_on = None
32def upgrade() -> None:
33 # ### commands auto generated by Alembic - please adjust! ###
34 op.create_table(
35 "client_identities",
36 sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
37 sa.Column("instance", sa.String(), nullable=False),
38 sa.Column("workflow", sa.String(), nullable=False),
39 sa.Column("actor", sa.String(), nullable=False),
40 sa.Column("subject", sa.String(), nullable=False),
41 sa.PrimaryKeyConstraint("id"),
42 sa.UniqueConstraint("instance", "workflow", "actor", "subject"),
43 )
45 # Adjusted by using batch_op and supplying a constraint name to be compatible with SQLight
46 with op.batch_alter_table("operations") as batch_op:
47 batch_op.add_column(sa.Column("client_identity_id", sa.Integer(), nullable=True))
48 batch_op.create_foreign_key(
49 "operation__client_identities_id", "client_identities", ["client_identity_id"], ["id"]
50 )
51 # ### end Alembic commands ###
54def downgrade() -> None:
55 # ### commands auto generated by Alembic - please adjust! ###
57 # Adjusted by using batch_op and supplying a constraint name to be compatible with SQLight
58 with op.batch_alter_table("operations") as batch_op:
59 batch_op.drop_constraint("operation__client_identities_id", type_="foreignkey")
60 batch_op.drop_column("client_identity_id")
61 op.drop_table("client_identities")
62 # ### end Alembic commands ###