runbot/runbot_merge/migrations/13.0.1.5/pre-migration.py
Xavier Morel c78ffb9e3f [CHG] runbot_merge: branch_ids -> branch_filter
On per-repo status configurations, convert the "branch_ids" filter to
a domain on branches. Since the selection is generally
binary (statuses either apply to the master branch or apply to
non-master branch) this avoids error-prone missed updates where we
forget to enable statuses pretty much every time we fork off a new
branch.

Fixes #404
2020-10-02 15:28:36 +02:00

23 lines
663 B
Python

def migrate(cr, version):
""" copy required status filters from an m2m to branches to a domain
"""
cr.execute("""
ALTER TABLE runbot_merge_repository_status
ADD COLUMN branch_filter varchar
""")
cr.execute('''
SELECT status_id, array_agg(branch_id)
FROM runbot_merge_repository_status_branch
GROUP BY status_id
''')
for st, brs in cr.fetchall():
cr.execute("""
UPDATE runbot_merge_repository_status
SET branch_filter = %s
WHERE id = %s
""", [
repr([('id', 'in', brs)]),
st
])
cr.execute("DROP TABLE runbot_merge_repository_status_branch")