From 2fb85c515e4b17fc3e12584a8d70c850cac4ba55 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 7 Jun 2024 17:05:58 +0200 Subject: [PATCH] [ADD] runbot_merge: missing staging migration 44084e303ccece3cb54128ab29eab399bd4d24e9 changed the interpretation and schema of the `statuses_cache` field on stagings, but I forgot to add a migration, so it would just blow up on opening the home dashboard or the staging lists. --- runbot_merge/__manifest__.py | 2 +- .../migrations/15.0.1.15/pre-migration.py | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 runbot_merge/migrations/15.0.1.15/pre-migration.py diff --git a/runbot_merge/__manifest__.py b/runbot_merge/__manifest__.py index 5f23262c..a21ce712 100644 --- a/runbot_merge/__manifest__.py +++ b/runbot_merge/__manifest__.py @@ -1,6 +1,6 @@ { 'name': 'merge bot', - 'version': '1.14', + 'version': '1.15', 'depends': ['contacts', 'mail', 'website'], 'data': [ 'security/security.xml', diff --git a/runbot_merge/migrations/15.0.1.15/pre-migration.py b/runbot_merge/migrations/15.0.1.15/pre-migration.py new file mode 100644 index 00000000..531811dd --- /dev/null +++ b/runbot_merge/migrations/15.0.1.15/pre-migration.py @@ -0,0 +1,22 @@ +"""Completely missed that in 44084e303ccece3cb54128ab29eab399bd4d24e9 I +completely changed the semantics and structure of the statuses_cache, so the +old caches don't actually work anymore at all. + +This rewrites all existing caches. +""" +def migrate(cr, version): + cr.execute(""" +WITH statuses AS ( + SELECT + s.id as staging_id, + json_object_agg(c.sha, c.statuses::json) as statuses + FROM runbot_merge_stagings s + LEFT JOIN runbot_merge_stagings_heads h ON (h.staging_id = s.id) + LEFT JOIN runbot_merge_commit c ON (h.commit_id = c.id) + GROUP BY s.id +) +UPDATE runbot_merge_stagings +SET statuses_cache = statuses +FROM statuses +WHERE id = staging_id + """)