mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
Merge pull request #335 from alphagov/fix-history-data
Data migration script to fix templates_history.updated_at.
This commit is contained in:
23
migrations/versions/0020_template_history_fix.py
Normal file
23
migrations/versions/0020_template_history_fix.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 0020_template_history_fix
|
||||||
|
Revises: 0019_add_job_row_number
|
||||||
|
Create Date: 2016-05-20 15:15:03.850862
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '0020_template_history_fix'
|
||||||
|
down_revision = '0019_add_job_row_number'
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.get_bind()
|
||||||
|
op.execute('update templates_history t set updated_at = (select updated_at from templates_history th where t.version = th.version -1 and t.id = th.id and t.version != 1)')
|
||||||
|
op.execute('update templates_history th set updated_at = (select t.updated_at from templates_history h, templates t where h.id = t.id and h.version = t.version and th.id = h.id) where (th.id, th.version) = (select t.id, t.version from templates t where t.id = th.id and t.version = th.version)')
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
pass
|
||||||
Reference in New Issue
Block a user