Files
notifications-api/migrations/versions/0014_add_template_version.py

47 lines
1.5 KiB
Python
Raw Normal View History

"""empty message
Revision ID: 0014_add_template_version
2023-07-19 09:19:40 -07:00
Revises: 0012_complete_provider_details
Create Date: 2016-05-11 16:00:51.478012
"""
# revision identifiers, used by Alembic.
2023-08-29 14:54:30 -07:00
revision = "0014_add_template_version"
down_revision = "0012_complete_provider_details"
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
2023-08-29 14:54:30 -07:00
def upgrade():
2023-08-29 14:54:30 -07:00
op.add_column("jobs", sa.Column("template_version", sa.Integer(), nullable=True))
op.get_bind()
2023-08-29 14:54:30 -07:00
op.execute(
"update jobs set template_version = (select version from templates where id = template_id)"
)
op.add_column(
"notifications", sa.Column("template_version", sa.Integer(), nullable=True)
)
op.execute(
"update notifications set template_version = (select version from templates where id = template_id)"
)
op.alter_column("jobs", "template_version", nullable=False)
op.alter_column("notifications", "template_version", nullable=False)
# fix template_history where created_by_id is not set.
2023-08-29 14:54:30 -07:00
query = (
"update templates_history set created_by_id = "
" (select created_by_id from templates "
" where templates.id = templates_history.id "
" and templates.version = templates_history.version) "
"where templates_history.created_by_id is null"
)
op.execute(query)
def downgrade():
2023-08-29 14:54:30 -07:00
op.drop_column("notifications", "template_version")
op.drop_column("jobs", "template_version")