Skip to Content

Contributors

Re: Rename a module with migration script

You can't do the operation from the migrations scripts of the module with the new name itself, as they are not going to be ever triggered.


Regards.

by Pedro M. Baeza - 08:15 - 29 Apr 2021

Reference

  • Rename a module with migration script
    Hello all!
    We are trying to rename a module. The main purpose is to change the
    name of the module itself, as well as xmlids, models and tables.
    
    Preliminary step:
    - Add a pre-migrate script like this one in new_name_module (bumping
    the version number):
    https://github.com/OCA/l10n-italy/pull/2220/commits/d6c790525e1892be1d04391054ccb779092c354c#diff-a86bc87cb07b27f04908e90baeb089a9182ad568d8e7205f40f3e689272bb76c
    
    Test steps:
    
    1) old_name module installation
    2) add/change some data in Odoo
    3) checkout to commit containing new_name module, migration script and
    version bumped
    4) launch old_name_module update:
    ./odoo-bin -c etc/odoo14.cfg -d testdb -u old_name_module --stop-after-init
    
    Output:
    old_name_module: not installable, skipped
    
    In fact pre-migrate script is not triggered.
    
    
    As an alternative to 4), we tried this:
    4) launch new_name_module update:
    ./odoo-bin -c etc/odoo14.cfg -d testdb -u new_name_module --stop-after-init
    
    But it didn't work as well.
    
    
    The only way (we have found so far) to trigger pre-migrate script is this:
    
    1) old_name module installation
    2) add/change some data
    3) checkout to commit containing new_name module, migration script and
    version bumped
    4) execute odoo shell
        >>> from openupgradelib import openupgrade
        >>> openupgrade.update_module_names(env.cr, [('old_name_module',
    'new_name_module'),], merge_modules=False,)
        >>> env.cr.commit()
    5) launch new_name_module update:
    ./odoo-bin -c etc/odoo14.cfg -d testdb -u new_name_module --stop-after-init
    
    
    Do you know a way to trigger the migration script without using odoo shell?
    
    Thanks in advance.
    S.
    

    by Sergio Zanchetta - 10:16 - 28 Apr 2021