From dc928a601c26a0fcb3b87d820167733662bd9f22 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Fri, 30 Nov 2018 17:35:57 +0100 Subject: [PATCH] [FIX] base_exception: Migration scripts Current method doesn't work, as this module is not being migrated, but fresh-installed by dependencies of old `sale_exception`, so we should use the pre_init_hook and detect if we should run the migration code according the existence of the table. --- base_exception/__init__.py | 2 +- base_exception/__manifest__.py | 1 + base_exception/hooks.py | 17 +++++++++++++++++ .../migrations/10.0.1.0.0/pre-migration.py | 12 ------------ 4 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 base_exception/hooks.py delete mode 100644 base_exception/migrations/10.0.1.0.0/pre-migration.py diff --git a/base_exception/__init__.py b/base_exception/__init__.py index 3c4dc4909..01e5383e5 100644 --- a/base_exception/__init__.py +++ b/base_exception/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# © 2011 Raphaël Valyi, Renato Lima, Guewen Baconnier, Sodexis # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import wizard, models +from .hooks import pre_init_hook diff --git a/base_exception/__manifest__.py b/base_exception/__manifest__.py index 6a42b0b1b..422e24dfb 100644 --- a/base_exception/__manifest__.py +++ b/base_exception/__manifest__.py @@ -18,4 +18,5 @@ 'views/base_exception_view.xml', ], 'installable': True, + 'pre_init_hook': 'pre_init_hook', } diff --git a/base_exception/hooks.py b/base_exception/hooks.py new file mode 100644 index 000000000..9a1f8ba38 --- /dev/null +++ b/base_exception/hooks.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Akretion, Mourad EL HADJ MIMOUNE +# Copyright 2018 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + + +def pre_init_hook(cr): + """If coming from v9 where only `sale_exception` is installed, when + auto-installing this one by dependencies, we should take care of + renaming previous table before the new model is loaded. + """ + cr.execute("SELECT 1 FROM pg_class WHERE relname = 'sale_exception'") + if not cr.fetchone(): + return # fresh install, so exiting + from openupgradelib import openupgrade + openupgrade.rename_tables(cr, [('sale_exception', 'exception_rule')]) + openupgrade.rename_models(cr, [('sale.exception', 'exception.rule')]) diff --git a/base_exception/migrations/10.0.1.0.0/pre-migration.py b/base_exception/migrations/10.0.1.0.0/pre-migration.py deleted file mode 100644 index 35600697f..000000000 --- a/base_exception/migrations/10.0.1.0.0/pre-migration.py +++ /dev/null @@ -1,12 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2017 Akretion, Mourad EL HADJ MIMOUNE -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). - -from openupgradelib import openupgrade - - -@openupgrade.migrate(use_env=True) -def migrate(env, version): - cr = env.cr - openupgrade.rename_tables(cr, [('sale_exception', 'exception_rule')]) - openupgrade.rename_models(cr, [('sale.exception', 'exception.rule')])