Browse Source

[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.
pull/1441/head
Pedro M. Baeza 6 years ago
parent
commit
dc928a601c
  1. 2
      base_exception/__init__.py
  2. 1
      base_exception/__manifest__.py
  3. 17
      base_exception/hooks.py
  4. 12
      base_exception/migrations/10.0.1.0.0/pre-migration.py

2
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

1
base_exception/__manifest__.py

@ -18,4 +18,5 @@
'views/base_exception_view.xml',
],
'installable': True,
'pre_init_hook': 'pre_init_hook',
}

17
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')])

12
base_exception/migrations/10.0.1.0.0/pre-migration.py

@ -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')])
Loading…
Cancel
Save