Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
fix(migrations): ignore missing percent_change
Browse files Browse the repository at this point in the history
Some very old triggered alerts don't have percent_change.
  • Loading branch information
Samyak2 committed Sep 30, 2022
1 parent e877300 commit a8fb6a9
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ def upgrade():

if "alert_data" in alert_metadata:
for data in alert_metadata["alert_data"]:
data["_old_percent_change"] = data.pop("percent_change")
if "percent_change" in data:
data["_old_percent_change"] = data.pop("percent_change")

for subdim_data in data.get("relevant_subdims_", []) or []:
subdim_data["_old_percent_change"] = subdim_data.pop(
"percent_change"
)
if "percent_change" in subdim_data:
subdim_data["_old_percent_change"] = subdim_data.pop(
"percent_change"
)

conn.execute(
sa.text(
Expand All @@ -58,12 +60,14 @@ def downgrade():

if "alert_data" in alert_metadata:
for data in alert_metadata["alert_data"]:
data["percent_change"] = data.pop("_old_percent_change")
if "_old_percent_change" in data:
data["percent_change"] = data.pop("_old_percent_change")

for subdim_data in data.get("relevant_subdims_", []) or []:
subdim_data["percent_change"] = subdim_data.pop(
"_old_percent_change"
)
if "_old_percent_change" in subdim_data:
subdim_data["percent_change"] = subdim_data.pop(
"_old_percent_change"
)

conn.execute(
sa.text(
Expand Down

0 comments on commit a8fb6a9

Please sign in to comment.