Skip to content

Commit

Permalink
feat(migrations): handle old import reports
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnisDa committed Jan 12, 2025
1 parent bc6c2b0 commit 4f492fe
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions crates/migrations/src/m20250112_changes_for_issue_1174.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,31 @@ ALTER TABLE "import_report" ALTER COLUMN "estimated_finish_time" SET NOT NULL;
)
.await?;
}
for enum_name in ["ReviewConversion", "SeenHistoryConversion"] {
db.execute_unprepared(&format!(
r#"
UPDATE import_report
SET details = jsonb_set(
details,
'{{failed_items}}',
(
SELECT jsonb_agg(
CASE
WHEN (failed_item ->> 'step') = '{enum_name}' THEN
jsonb_set(failed_item, '{{step}}', '"DatabaseCommit"')
ELSE
failed_item
END
)
FROM jsonb_array_elements(details -> 'failed_items') AS failed_item
)
)
WHERE details -> 'failed_items' @> '[{{"step": "{enum_name}"}}]';
"#,
enum_name = enum_name
))
.await?;
}
Ok(())
}

Expand Down

0 comments on commit 4f492fe

Please sign in to comment.