Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] migrate_translations_to_jsonb: avoid ir_translation terms cleanup #374

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions openupgradelib/openupgrade_160.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""This module provides simple tools for OpenUpgrade migration, specific for
the >=16.0 migration.
"""
import itertools
import logging
from itertools import product

Expand Down Expand Up @@ -46,20 +45,25 @@ def migrate_translations_to_jsonb(env, fields_spec):

:param fields_spec: list of tuples of (model name, field name)
"""
initial_translation_tables = None
# Odoo's core method expects to have the former `ir_tanslation` table renamed. If
# we don't, it's going to fail as it tries to execute queries on it
rename_translation_table = table_exists(env.cr, "ir_translation")
if rename_translation_table:
logged_query(env.cr, "ALTER TABLE ir_translation RENAME TO _ir_translation")
if table_exists(env.cr, "_ir_translation"):
initial_translation_tables = "_ir_translation"
elif table_exists(env.cr, "ir_translation"):
initial_translation_tables = "ir_translation"
if initial_translation_tables:
for model, field_name in fields_spec:
field = env[model]._fields[field_name]
for query in itertools.chain.from_iterable(
_get_translation_upgrade_queries(env.cr, field)
):
if initial_translation_tables == "ir_translation":
query = query.replace("_ir_translation", "ir_translation")
# Ignore cleanup queries as we want to keep the original ir_translation
# table records in order to be able to fix possible inconsistencies once
# we're migrated.
migrate_queries, _cleanup_queries = _get_translation_upgrade_queries(
env.cr, field
)
for query in migrate_queries:
logged_query(env.cr, query)
# Just leave it as it was if we renamed it
if rename_translation_table:
logged_query(env.cr, "ALTER TABLE _ir_translation RENAME TO ir_translation")


_BADGE_CONTEXTS = (
Expand Down
Loading