diff --git a/base_comment_template/migrations/15.0.1.1.0/pre-migration.py b/base_comment_template/migrations/15.0.1.1.0/pre-migration.py index a22b2bdfc..3aaf7ce51 100644 --- a/base_comment_template/migrations/15.0.1.1.0/pre-migration.py +++ b/base_comment_template/migrations/15.0.1.1.0/pre-migration.py @@ -6,18 +6,20 @@ from openupgradelib import openupgrade @openupgrade.migrate() def migrate(env, version): - openupgrade.logged_query( - env.cr, "ALTER TABLE base_comment_template ADD COLUMN IF NOT EXISTS models text" - ) - openupgrade.logged_query( - env.cr, - """ - UPDATE base_comment_template template - SET models = ( - SELECT string_agg(model.model, ',') - FROM base_comment_template_ir_model_rel AS rel - JOIN ir_model AS model ON rel.ir_model_id = model.id - WHERE rel.base_comment_template_id = template.id + if openupgrade.table_exists(env.cr, "base_comment_template_ir_model_rel"): + openupgrade.logged_query( + env.cr, + "ALTER TABLE base_comment_template ADD COLUMN IF NOT EXISTS models text", + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE base_comment_template template + SET models = ( + SELECT string_agg(model.model, ',') + FROM base_comment_template_ir_model_rel AS rel + JOIN ir_model AS model ON rel.ir_model_id = model.id + WHERE rel.base_comment_template_id = template.id + ) + """, ) - """, - )