mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
- The name of the columns were swapped, so better to fix it for avoiding mistakes due to this. - Migration script for detecting the condition and swap column names. - On v12 > v13 migration, include JOINs for avoiding FK constraint, which `ON CONFLICT` clause doesn't protect.
27 lines
886 B
Python
27 lines
886 B
Python
# Copyright 2021 Tecnativa - Víctor Martínez
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
|
from openupgradelib import openupgrade
|
|
|
|
field_renames = [
|
|
("base.comment.template", "base_comment_template", "priority", "sequence"),
|
|
]
|
|
|
|
|
|
@openupgrade.migrate()
|
|
def migrate(env, version):
|
|
# Not tested
|
|
openupgrade.logged_query(
|
|
env.cr,
|
|
"""
|
|
INSERT INTO base_comment_template_res_partner_rel
|
|
(res_partner_id, base_comment_template_id)
|
|
SELECT SPLIT_PART(ip.res_id, ',', 2)::int AS res_partner_id,
|
|
SPLIT_PART(ip.value_reference, ',', 2)::int AS base_comment_template_id
|
|
FROM ir_property ip
|
|
JOIN ir_model_fields imf ON ip.fields_id = imf.id
|
|
WHERE imf.name = 'property_comment_template_id'
|
|
AND imf.model = 'res.partner'
|
|
""",
|
|
)
|
|
openupgrade.rename_fields(env, field_renames)
|