OpenUpgrade is an opensource OCA tool which allows upgrading Odoo database from one major version to another. It can be used for upgrading community database. With OpenUpgrade, we can only upgrade to the next immediate version one at a time. Therefore, to upgrade the database from v14.0 to v16.0, we first need to upgrade from v14.0 to v15.0, then from v15.0 to v16.0.

This blog outlines a step-by-step process for using OpenUpgrade to migrate an Odoo database from version 14 to 16.

To fully understand this document, you should have familiarity with the Odoo ecosystem and its configurations.

Create a Backup of the Odoo Database

First, back up the database you want to upgrade. You can do this through the Odoo interface or via the command line (using pg_dump). Regardless of the method, ensure you include the filestore, which contains files and images, in your backup.

Restore Database Backup

Once the backup of the Odoo 14 database is ready, restore it in version 15. This can be accomplished either through the ‘Restore Database’ option in the Odoo interface or via the command line. To restore the database through the command line, you can:

Stop Odoo server

sudo service odoo14-server stop

Switch to Odoo user

sudo su odoo

Create new database

createdb -O odoo database_name

Restore the database backup

psql database_name < v14_backup.sql

When performing a database restoration via the command line, ensure that you accurately include the filestore. The database name and filestore name should match, ensuring Odoo utilises the same filestore instead of generating a new one. Odoo stores the filestore in /home/odoo/.local/share/Odoo/filestore (assuming /home/odoo is Odoo’s home directory).

Upgrade Odoo Database

Since the database is not yet upgraded, Odoo will display an incompatibility error. To upgrade the database, we need to install certain packages. With OpenUpgrade, scripts are run on the upgraded version. For example, when upgrading from version 14 to 15, scripts will be executed on the version 15 server.

  1. Download the migration scripts from OpenUpgrade which will be used to upgrade database. Since we are upgrading to version 15.0, we will clone 15.0 branch
git clone --branch=15.0 --depth=1 --single-branch <https://github.com/OCA/OpenUpgrade.git> openupgrade_15

2. Next, install a python package openupgradelib which can be done using pip as well

pip3 install openupgradelib

3. Once required packages are downloaded, let’s create a new odoo config file which includes migration scripts

sudo nano odoo14_15.conf
[options]
db_host = False
db_port = 5432
db_user = odoo
db_password = False
addons_path = /home/odoo/odoo/addons,/home/odoo/openupgrade_15

Save above file and make sure it has all necessary permissions set for odoo user to run it.

4. Stop Odoo 15 server

sudo service odoo15-server stop

5. Now, run the migration script to upgrade the database

sudo su odoo
odoo/odoo-bin -c /etc/odoo14_15.conf --database=database_to_upgrade --upgrade-path=/home/odoo/openupgrade_15/openupgrade_scripts/scripts --load=base,web,openupgrade_framework --update all --stop-after-init

The OpenUpgrade structure has changed from Odoo version 14 onwards. So, step 3 and 5 will be bit different when upgrading database to and before version 13.

Once the migration script runs successfully, restart the database and you will see a compatible upgraded database.

Bug Fixes After Upgrade

If there are any errors during migration, we need to manually fix those errors and re-run the script. This is repetitive process which might need data cleanup, bug fixes. To avoid issues during upgrade, make sure to

  • Thoroughly clean up your data to prevent any issues that could lead to errors
  • Ensure that custom modules are upgraded to the target version.
  • Maintain consistency in field names, data types, and external IDs within custom modules.
  • If there are modifications to field names, data types, or the database structure, it’s necessary to create migration scripts for custom modules. The OpenUpgrade API offers all the necessary helper methods to facilitate the creation of these migration scripts.

Now repeat the above process for upgrading database from version 15 to version 16.

Source: Upgrade Odoo Database (Community Version) with OpenUpgrade | by Karan Bishwakarma | Medium