migrations updates:
- retain relevant task order data when migrating request bodies - set revision relationship for status events - make relationship between status events and revisions not nullable
This commit is contained in:
parent
9cbcba5101
commit
7ab313b100
@ -0,0 +1,32 @@
|
||||
"""make status event relation to revision non-nullable
|
||||
|
||||
Revision ID: 06aa23166ca9
|
||||
Revises: e66a49285f23
|
||||
Create Date: 2018-09-04 15:03:20.299607
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '06aa23166ca9'
|
||||
down_revision = 'e66a49285f23'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.alter_column('request_status_events', 'request_revision_id',
|
||||
existing_type=postgresql.UUID(),
|
||||
nullable=False)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.alter_column('request_status_events', 'request_revision_id',
|
||||
existing_type=postgresql.UUID(),
|
||||
nullable=True)
|
||||
# ### end Alembic commands ###
|
@ -13,6 +13,7 @@ from sqlalchemy.dialects import postgresql
|
||||
from atst.models.request import Request
|
||||
from atst.utils import deep_merge
|
||||
from atst.domain.requests import create_revision_from_request_body
|
||||
from atst.domain.task_orders import TaskOrders
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
@ -30,9 +31,21 @@ def delete_two_deep(body, key1, key2):
|
||||
return body
|
||||
|
||||
|
||||
TASK_ORDER_DATA = TaskOrders.TASK_ORDER_DATA + ["task_order_id", "csrf_token"]
|
||||
|
||||
def create_revision(body):
|
||||
financials = body.get("financial_verification")
|
||||
if financials:
|
||||
for column in TASK_ORDER_DATA:
|
||||
if column in financials:
|
||||
del(financials[column])
|
||||
|
||||
return create_revision_from_request_body(body)
|
||||
|
||||
|
||||
def massaged_revision(body):
|
||||
try:
|
||||
return create_revision_from_request_body(body)
|
||||
return create_revision(body)
|
||||
except ValueError:
|
||||
# some of the data on staging has out-of-range dates like "02/29/2019";
|
||||
# we don't know how to coerce them to valid dates, so we remove those
|
||||
@ -40,8 +53,9 @@ def massaged_revision(body):
|
||||
body = delete_two_deep(body, "details_of_use", "start_date")
|
||||
body = delete_two_deep(body, "information_about_you", "date_latest_training")
|
||||
|
||||
return create_revision_from_request_body(body)
|
||||
return create_revision(body)
|
||||
|
||||
from uuid import UUID
|
||||
|
||||
def upgrade():
|
||||
Session = sessionmaker(bind=op.get_bind())
|
||||
@ -49,14 +63,14 @@ def upgrade():
|
||||
for request in session.query(Request).all():
|
||||
(body,) = session.execute("SELECT body from requests WHERE id='{}'".format(request.id)).fetchone()
|
||||
|
||||
# this data should already exist as a task_order
|
||||
if body.get("financial_verification"):
|
||||
del(body["financial_verification"])
|
||||
|
||||
revision = massaged_revision(body)
|
||||
request.revisions.append(revision)
|
||||
|
||||
session.add(revision)
|
||||
session.add(request)
|
||||
|
||||
session.commit()
|
||||
|
||||
op.drop_column('requests', 'body')
|
||||
|
||||
|
||||
|
@ -7,20 +7,32 @@ Create Date: 2018-09-04 14:01:31.548665
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
from atst.models.request import Request
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'e66a49285f23'
|
||||
down_revision = '090e1bd0d7ce'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
from uuid import UUID
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('request_status_events', sa.Column('request_revision_id', postgresql.UUID(as_uuid=True), nullable=False))
|
||||
op.add_column('request_status_events', sa.Column('request_revision_id', postgresql.UUID(as_uuid=True)))
|
||||
op.create_foreign_key(None, 'request_status_events', 'request_revisions', ['request_revision_id'], ['id'])
|
||||
# ### end Alembic commands ###
|
||||
|
||||
Session = sessionmaker(bind=op.get_bind())
|
||||
session = Session()
|
||||
for request in session.query(Request).all():
|
||||
for status in request.status_events:
|
||||
status.revision = request.latest_revision
|
||||
session.add(status)
|
||||
|
||||
session.commit()
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
Loading…
x
Reference in New Issue
Block a user