[ADD] runbot_merge: missing staging migration

44084e303c 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.
This commit is contained in:
Xavier Morel 2024-06-07 17:05:58 +02:00
parent f4035932e3
commit 2fb85c515e
2 changed files with 23 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{
'name': 'merge bot',
'version': '1.14',
'version': '1.15',
'depends': ['contacts', 'mail', 'website'],
'data': [
'security/security.xml',

View File

@ -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
""")