|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | +# you may not use this file except in compliance with the License. |
| 3 | +# You may obtain a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +# See the License for the specific language governing permissions and |
| 11 | +# limitations under the License. |
| 12 | +""" |
| 13 | +Add Buildkite OIDC models |
| 14 | +
|
| 15 | +Revision ID: 8c83f0a1d70e |
| 16 | +Revises: 186f076eb60b |
| 17 | +Create Date: 2023-10-27 09:20:18.030874 |
| 18 | +""" |
| 19 | + |
| 20 | +import sqlalchemy as sa |
| 21 | + |
| 22 | +from alembic import op |
| 23 | + |
| 24 | +revision = "8c83f0a1d70e" |
| 25 | +down_revision = "186f076eb60b" |
| 26 | + |
| 27 | +# Note: It is VERY important to ensure that a migration does not lock for a |
| 28 | +# long period of time and to ensure that each individual migration does |
| 29 | +# not break compatibility with the *previous* version of the code base. |
| 30 | +# This is because the migrations will be ran automatically as part of the |
| 31 | +# deployment process, but while the previous version of the code is still |
| 32 | +# up and running. Thus backwards incompatible changes must be broken up |
| 33 | +# over multiple migrations inside of multiple pull requests in order to |
| 34 | +# phase them in over multiple deploys. |
| 35 | +# |
| 36 | +# By default, migrations cannot wait more than 4s on acquiring a lock |
| 37 | +# and each individual statement cannot take more than 5s. This helps |
| 38 | +# prevent situations where a slow migration takes the entire site down. |
| 39 | +# |
| 40 | +# If you need to increase this timeout for a migration, you can do so |
| 41 | +# by adding: |
| 42 | +# |
| 43 | +# op.execute("SET statement_timeout = 5000") |
| 44 | +# op.execute("SET lock_timeout = 4000") |
| 45 | +# |
| 46 | +# To whatever values are reasonable for this migration as part of your |
| 47 | +# migration. |
| 48 | + |
| 49 | + |
| 50 | +def upgrade(): |
| 51 | + # ### commands auto generated by Alembic - please adjust! ### |
| 52 | + op.create_table( |
| 53 | + "buildkite_oidc_publishers", |
| 54 | + sa.Column("id", sa.UUID(), nullable=False), |
| 55 | + sa.Column("organization_slug", sa.String(), nullable=False), |
| 56 | + sa.Column("pipeline_slug", sa.String(), nullable=False), |
| 57 | + sa.Column("build_branch", sa.String(), nullable=False), |
| 58 | + sa.Column("build_tag", sa.String(), nullable=False), |
| 59 | + sa.Column("step_key", sa.String(), nullable=False), |
| 60 | + sa.ForeignKeyConstraint( |
| 61 | + ["id"], |
| 62 | + ["oidc_publishers.id"], |
| 63 | + ), |
| 64 | + sa.PrimaryKeyConstraint("id"), |
| 65 | + sa.UniqueConstraint( |
| 66 | + "organization_slug", "pipeline_slug", name="_buildkite_oidc_publisher_uc" |
| 67 | + ), |
| 68 | + ) |
| 69 | + op.create_table( |
| 70 | + "pending_buildkite_oidc_publishers", |
| 71 | + sa.Column("id", sa.UUID(), nullable=False), |
| 72 | + sa.Column("organization_slug", sa.String(), nullable=False), |
| 73 | + sa.Column("pipeline_slug", sa.String(), nullable=False), |
| 74 | + sa.Column("build_branch", sa.String(), nullable=False), |
| 75 | + sa.Column("build_tag", sa.String(), nullable=False), |
| 76 | + sa.Column("step_key", sa.String(), nullable=False), |
| 77 | + sa.ForeignKeyConstraint( |
| 78 | + ["id"], |
| 79 | + ["pending_oidc_publishers.id"], |
| 80 | + ), |
| 81 | + sa.PrimaryKeyConstraint("id"), |
| 82 | + sa.UniqueConstraint( |
| 83 | + "organization_slug", |
| 84 | + "pipeline_slug", |
| 85 | + name="_pending_buildkite_oidc_publisher_uc", |
| 86 | + ), |
| 87 | + ) |
| 88 | + # ### end Alembic commands ### |
| 89 | + |
| 90 | + |
| 91 | +def downgrade(): |
| 92 | + # ### commands auto generated by Alembic - please adjust! ### |
| 93 | + op.drop_table("pending_buildkite_oidc_publishers") |
| 94 | + op.drop_table("buildkite_oidc_publishers") |
| 95 | + # ### end Alembic commands ### |
0 commit comments