|
| 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 Project Lifecycle Status |
| 14 | +
|
| 15 | +Revision ID: 14ad61e054cf |
| 16 | +Revises: b14df478c48f |
| 17 | +Create Date: 2024-06-26 20:30:52.083447 |
| 18 | +""" |
| 19 | + |
| 20 | +import sqlalchemy as sa |
| 21 | + |
| 22 | +from alembic import op |
| 23 | +from sqlalchemy.dialects import postgresql |
| 24 | + |
| 25 | +revision = "14ad61e054cf" |
| 26 | +down_revision = "b14df478c48f" |
| 27 | + |
| 28 | + |
| 29 | +def upgrade(): |
| 30 | + op.execute("SET statement_timeout = 5000") |
| 31 | + op.execute("SET lock_timeout = 4000") |
| 32 | + |
| 33 | + sa.Enum("quarantine-enter", "quarantine-exit", name="lifecyclestatus").create( |
| 34 | + op.get_bind() |
| 35 | + ) |
| 36 | + op.add_column( |
| 37 | + "projects", |
| 38 | + sa.Column( |
| 39 | + "lifecycle_status", |
| 40 | + postgresql.ENUM( |
| 41 | + "quarantine-enter", |
| 42 | + "quarantine-exit", |
| 43 | + name="lifecyclestatus", |
| 44 | + create_type=False, |
| 45 | + ), |
| 46 | + nullable=True, |
| 47 | + comment="Lifecycle status can change project visibility and access", |
| 48 | + ), |
| 49 | + ) |
| 50 | + op.add_column( |
| 51 | + "projects", |
| 52 | + sa.Column( |
| 53 | + "lifecycle_status_changed", |
| 54 | + sa.DateTime(), |
| 55 | + server_default=sa.text("now()"), |
| 56 | + nullable=True, |
| 57 | + comment="When the lifecycle status was last changed", |
| 58 | + ), |
| 59 | + ) |
| 60 | + op.add_column( |
| 61 | + "projects", |
| 62 | + sa.Column( |
| 63 | + "lifecycle_status_note", |
| 64 | + sa.String(), |
| 65 | + nullable=True, |
| 66 | + comment="Note about the lifecycle status", |
| 67 | + ), |
| 68 | + ) |
| 69 | + op.create_index( |
| 70 | + "projects_lifecycle_status_idx", "projects", ["lifecycle_status"], unique=False |
| 71 | + ) |
| 72 | + |
| 73 | + |
| 74 | +def downgrade(): |
| 75 | + op.drop_index("projects_lifecycle_status_idx", table_name="projects") |
| 76 | + op.drop_column("projects", "lifecycle_status_note") |
| 77 | + op.drop_column("projects", "lifecycle_status_changed") |
| 78 | + op.drop_column("projects", "lifecycle_status") |
| 79 | + sa.Enum("quarantine-enter", "quarantine-exit", name="lifecyclestatus").drop( |
| 80 | + op.get_bind() |
| 81 | + ) |
0 commit comments