runbot/runbot_merge/migrations/15.0.1.15/pre-migration.py
Xavier Morel 2fb85c515e [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.
2024-06-07 17:05:58 +02:00

23 lines
686 B
Python

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