Skip to content

Commit

Permalink
expand migration downgrade step, to remove all sequential hard domain…
Browse files Browse the repository at this point in the history
… counts, so the test db can be switched over to a hotfix without this migration.
  • Loading branch information
pbugni committed Sep 20, 2023
1 parent c0fac93 commit 4a53cde
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion portal/migrations/versions/80c3b1e96c45_.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,33 @@ def upgrade():


def downgrade():
pass # no value in removing
# for each active EMPRO patient with at least 1 hard triggered domain,
# remove any sequential counts found
bind = op.get_bind()
session = Session(bind=bind)

patient_ids = []
for patient_id in session.execute(
"SELECT DISTINCT(user_id) FROM trigger_states JOIN users"
" ON users.id = user_id WHERE deleted_id IS NULL"):
patient_ids.append(patient_id[0])

output = StringIO()
for pid in patient_ids:
output.write(f"\n\nPatient: {pid}\n")
trigger_states = db.session.query(TriggerState).filter(
TriggerState.user_id == pid).filter(
TriggerState.state == "resolved").order_by(
TriggerState.timestamp.asc())
for ts in trigger_states:
improved_triggers = deepcopy(ts.triggers)
for d in EMPRO_DOMAINS:
if sequential_hard_trigger_count_key in improved_triggers["domain"][d]:
del improved_triggers["domain"][d][sequential_hard_trigger_count_key]
output.write(f" removed sequential from {ts.visit_month}:{d} {improved_triggers['domain'][d]}\n")

# retain triggers now containing sequential counts
ts.triggers = improved_triggers

db.session.commit()
print(output.getvalue())

0 comments on commit 4a53cde

Please sign in to comment.