Files
notifications-api/migrations/versions/0078_add_sent_notification_status.py

67 lines
1.9 KiB
Python
Raw Normal View History

2017-04-25 16:29:07 +01:00
"""empty message
2017-04-26 16:54:24 +01:00
Revision ID: 0078_sent_notification_status
Revises: 0077_add_intl_notification
2017-04-25 16:29:07 +01:00
Create Date: 2017-04-24 16:55:20.731069
"""
# revision identifiers, used by Alembic.
2023-08-29 14:54:30 -07:00
revision = "0078_sent_notification_status"
down_revision = "0077_add_intl_notification"
2017-04-25 16:29:07 +01:00
import sqlalchemy as sa
from alembic import op
2017-04-25 16:29:07 +01:00
2023-08-29 14:54:30 -07:00
enum_name = "notify_status_type"
tmp_name = "tmp_" + enum_name
2017-04-25 16:29:07 +01:00
old_options = (
2023-08-29 14:54:30 -07:00
"created",
"sending",
"delivered",
"pending",
"failed",
"technical-failure",
"temporary-failure",
"permanent-failure",
2017-04-25 16:29:07 +01:00
)
2023-08-29 14:54:30 -07:00
new_options = old_options + ("sent",)
2017-04-25 16:29:07 +01:00
old_type = sa.Enum(*old_options, name=enum_name)
new_type = sa.Enum(*new_options, name=enum_name)
2023-08-29 14:54:30 -07:00
alter_str = "ALTER TABLE {table} ALTER COLUMN status TYPE {enum} USING status::text::notify_status_type "
2017-04-25 16:29:07 +01:00
2023-07-17 07:45:54 -07:00
2017-04-25 16:29:07 +01:00
def upgrade():
2023-08-29 14:54:30 -07:00
op.execute("ALTER TYPE notify_status_type RENAME TO tmp_notify_status_type")
2017-04-25 16:29:07 +01:00
new_type.create(op.get_bind())
2023-07-18 13:16:43 -07:00
op.execute(
2023-08-29 14:54:30 -07:00
"ALTER TABLE notifications ALTER COLUMN status TYPE notify_status_type USING status::text::notify_status_type"
)
op.execute(
"ALTER TABLE notification_history ALTER COLUMN status TYPE notify_status_type USING status::text::notify_status_type"
)
2017-04-25 16:29:07 +01:00
2023-08-29 14:54:30 -07:00
op.execute("DROP TYPE tmp_notify_status_type")
2017-04-25 16:29:07 +01:00
def downgrade():
2023-08-29 14:54:30 -07:00
op.execute("ALTER TYPE notify_status_type RENAME TO tmp_notify_status_type")
2017-04-25 16:29:07 +01:00
2023-07-18 13:16:43 -07:00
op.execute("UPDATE notifications SET status='sending' where status='sent'")
op.execute("UPDATE notification_history SET status='sending' where status='sent'")
2017-04-25 16:29:07 +01:00
old_type.create(op.get_bind())
2023-07-18 13:16:43 -07:00
op.execute(
2023-08-29 14:54:30 -07:00
"ALTER TABLE notifications ALTER COLUMN status TYPE notify_status_type USING status::text::notify_status_type"
)
op.execute(
"ALTER TABLE notification_history ALTER COLUMN status TYPE notify_status_type USING status::text::notify_status_type"
)
2017-04-25 16:29:07 +01:00
2023-08-29 14:54:30 -07:00
op.execute("DROP TYPE tmp_notify_status_type")