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: convert columns to jsonb #375

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
21 changes: 20 additions & 1 deletion openupgradelib/openupgrade_160.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@
from psycopg2 import sql
from psycopg2.extras import Json

from odoo import tools
from odoo.osv import expression
from odoo.tools.translate import _get_translation_upgrade_queries

from .openupgrade import logged_query, table_exists, update_field_multilang
from .openupgrade import (
get_model2table,
logged_query,
table_exists,
update_field_multilang,
)
from .openupgrade_tools import (
convert_html_fragment,
convert_html_replacement_class_shortcut as _r,
Expand Down Expand Up @@ -52,6 +58,19 @@ def migrate_translations_to_jsonb(env, fields_spec):
logged_query(env.cr, "ALTER TABLE ir_translation RENAME TO _ir_translation")
if table_exists(env.cr, "_ir_translation"):
for model, field_name in fields_spec:
table = get_model2table(model)
if not table_exists(env.cr, table):
logger.warning(
"Couldn't find table for model %s - not updating translations",
model,
)
continue
# Convert columns if needed
columns = tools.sql.table_columns(env.cr, table)
if columns.get(field_name, {}).get("udt_name", "") in ["varchar", "text"]:
tools.sql.convert_column_translatable(
env.cr, table, field_name, "jsonb"
)
field = env[model]._fields[field_name]
# Ignore cleanup queries as we want to keep the original ir_translation
# table records in order to be able to fix possible inconsistencies once
Expand Down
Loading