From fb841fb4e6c1cff05ca6a1ce9e246c838631dd40 Mon Sep 17 00:00:00 2001 From: Ivo Oskamp Date: Fri, 20 Mar 2026 12:04:24 +0100 Subject: [PATCH] Auto-commit local changes before build (2026-03-20 12:04:24) --- .../src/backend/app/migrations.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/containers/backupchecks/src/backend/app/migrations.py b/containers/backupchecks/src/backend/app/migrations.py index 6bb3ae7..fc8ff8c 100644 --- a/containers/backupchecks/src/backend/app/migrations.py +++ b/containers/backupchecks/src/backend/app/migrations.py @@ -1366,6 +1366,38 @@ def migrate_cc_accounts_repo_unique_key() -> None: print(f"[migrations] Failed migrate_cc_accounts_repo_unique_key: {exc}") +def migrate_cc_remove_synthetic_missed_runs() -> None: + """Remove synthetic missed runs that were incorrectly generated for Cloud Connect jobs. + + Cloud Connect jobs do not have a fixed schedule — the daily report email can arrive at + different times of day. The schedule-inference + missed-run generator would create phantom + 'missed' entries when the delivery time shifted (e.g. from 18:55 to 10:24). These are now + suppressed in code; this migration cleans up any that were already stored. + """ + try: + engine = db.get_engine() + except Exception as exc: + print(f"[migrations] Could not get engine for cc missed-run cleanup: {exc}") + return + + try: + with engine.begin() as conn: + result = conn.execute(text(""" + DELETE FROM job_runs + WHERE missed = true + AND mail_message_id IS NULL + AND external_id IS NULL + AND job_id IN ( + SELECT id FROM jobs + WHERE LOWER(backup_type) IN ('cloud connect backup', 'cloud connect agent') + ) + """)) + deleted = result.rowcount + print(f"[migrations] migrate_cc_remove_synthetic_missed_runs completed ({deleted} rows removed).") + except Exception as exc: + print(f"[migrations] Failed migrate_cc_remove_synthetic_missed_runs: {exc}") + + def run_migrations() -> None: print("[migrations] Starting migrations...") migrate_add_username_to_users() @@ -1413,6 +1445,7 @@ def run_migrations() -> None: migrate_cove_accounts_table() migrate_cloud_connect_accounts_table() migrate_cc_accounts_repo_unique_key() + migrate_cc_remove_synthetic_missed_runs() migrate_entra_sso_settings() print("[migrations] All migrations completed.")