mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05:00
More attempts with migration fun.
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
@@ -9,14 +9,31 @@ from re import I
|
|||||||
from alembic import op
|
from alembic import op
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
# Copied pattern for adjusting a enum as defined in 0359_more_permissions
|
||||||
|
|
||||||
revision = "0404_expire_invites"
|
revision = "0404_expire_invites"
|
||||||
down_revision = "0403_add_carrier"
|
down_revision = "0403_add_carrier"
|
||||||
|
|
||||||
|
enum_name = "invited_users_status_types"
|
||||||
|
tmp_name = "tmp_" + enum_name
|
||||||
|
|
||||||
|
old_options = ("pending", "accepted", "cancelled")
|
||||||
|
old_type = sa.Enum(*old_options, name=enum_name)
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
op.execute("insert into invite_status_type values ('expired')")
|
# ALTER TYPE must be run outside of a transaction block (see link below for details)
|
||||||
|
# https://alembic.sqlalchemy.org/en/latest/api/runtime.html#alembic.runtime.migration.MigrationContext.autocommit_block
|
||||||
|
with op.get_context().autocommit_block():
|
||||||
|
op.execute(f"ALTER TYPE {enum_name} ADD VALUE 'expired'")
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
op.execute("delete from invite_status_type where name = 'expired'")
|
op.execute(f"DELETE FROM invited_users WHERE status = 'expired'")
|
||||||
|
|
||||||
|
op.execute(f"ALTER TYPE {enum_name} RENAME TO {tmp_name}")
|
||||||
|
old_type.create(op.get_bind())
|
||||||
|
op.execute(
|
||||||
|
f"ALTER TABLE invited_users ALTER COLUMN status TYPE {enum_name} using status::text::{enum_name}"
|
||||||
|
)
|
||||||
|
op.execute(f"DROP TYPE {tmp_name}")
|
||||||
|
|||||||
Reference in New Issue
Block a user