1+ :show-content:
2+
13=============================
24Upgrade a customized database
35=============================
46
7+ .. toctree ::
8+ :titlesonly:
9+ :glob:
10+
11+ upgrade_custom_db/*
12+
513Upgrading to a new version of Odoo can be challenging, especially if the database you work on
614contains custom modules. This page intent is to explain the technical process of upgrading a
715database with customized modules. Refer to :doc: `Upgrade documentation </administration/upgrade >`
@@ -33,7 +41,6 @@ These are the steps to follow to upgrade customized databases:
3341#. :ref: `Test extensively and do a rehearsal <upgrade_custom/testing_rehearsal >`.
3442#. :ref: `Upgrade the production database <upgrade_custom/production >`.
3543
36-
3744.. _upgrade_custom/stop_developments :
3845
3946Step 1: Stop the developments
@@ -47,14 +54,13 @@ Needless to say, bug fixing is exempt from this recommendation.
4754Once you have stopped development, it is a good practice to assess the developments made and compare
4855them with the features introduced between your current version and the version you are targeting.
4956Challenge the developments as much as possible and find functional workarounds. Removing redundancy
50- between your developments and the standard version of Odoo will lead to an eased
51- upgrade process and reduce technical debt.
57+ between your developments and the standard version of Odoo will lead to an eased upgrade process
58+ and reduce technical debt.
5259
5360.. note ::
5461 You can find information on the changes between versions in the `Release Notes
5562 <https:/odoo.com/page/release-notes> `_.
5663
57-
5864.. _upgrade_custom/request_upgrade :
5965
6066Step 2: Request an upgraded database
@@ -71,7 +77,6 @@ properly. If that's not the case, and the upgrade request fails, request the ass
7177the `support page <https://odoo.com/help?stage=migration >`_ by selecting the option related to
7278testing the upgrade.
7379
74-
7580.. _upgrade_custom/empty_database :
7681
7782Step 3: Empty database
@@ -85,7 +90,7 @@ features, and guarantees that they will not cause any issues when upgrading the
8590Making the custom modules work in an empty database also helps avoid changes and wrong
8691configurations that might be present in the production database (like studio customization,
8792customized website pages, email templates or translations). They are not intrinsically related to
88- the custom modules and that can raise unwanted issues in this stage of the upgraded process.
93+ the custom modules and that can raise unwanted issues in this stage of the upgrade process.
8994
9095To make custom modules work on an empty database we advise to follow these steps:
9196
@@ -190,22 +195,48 @@ To make sure the custom code is working flawlessly in the new version, follow th
190195Migrate the data
191196----------------
192197
193- During the upgrade of the custom modules, you might have to use migration scripts to reflect changes
194- from the source code to their corresponding data.
198+ During the upgrade of the custom modules, you might have to use
199+ :doc: `upgrade scripts <upgrade_custom_db/upgrade_scripts >` to reflect changes from the source code
200+ to their corresponding data. Together with the upgrade scripts, you can also make use of the
201+ :doc: `../reference/upgrade_util ` and its helper functions.
195202
196203- Any technical data that was renamed during the upgrade of the custom code (models, fields,
197- external identifiers) should be renamed using migration scripts to avoid data loss during the
198- module upgrade.
204+ external identifiers) should be renamed using upgrade scripts to avoid data loss during the
205+ module upgrade. See also: :meth: ` rename_field `, :meth: ` rename_model `, :meth: ` rename_xmlid `.
199206- Data from standard models removed from the source code of the newer Odoo version and from the
200207 database during the standard upgrade process might need to be recovered from the old model table
201208 if it is still present.
202209
203- Migration scripts can also be used to:
210+ .. example ::
211+ Custom fields for model ``sale.subscription `` are not automatically migrated from Odoo 15 to
212+ Odoo 16 (when the model was merged into ``sale.order ``). In this case, a SQL query can be
213+ executed on an upgrade script to move the data from one table to the other. Take into account
214+ that all columns/fields must already exist, so consider doing this in a ``post- `` script (See
215+ :ref: `upgrade/upgrade-scripts/phases `).
216+
217+ .. spoiler ::
218+
219+ .. code-block :: python
220+
221+ def migrate (cr , version ):
222+ cr.execute(
223+ """
224+ UPDATE sale_order so
225+ SET custom_field = ss.custom_field
226+ FROM sale_subscription ss
227+ WHERE ss.new_sale_order_id = so.id
228+ """
229+ )
230+
231+ Check the documentation for more information on :doc: `upgrade_custom_db/upgrade_scripts `.
232+
233+ Upgrade scripts can also be used to:
204234
205235- Ease the processing time of an upgrade. For example, to store the value of computed stored fields
206236 on models with an excessive number of records by using SQL queries.
207- - Recompute fields in case the computation of their value has changed.
208- - Uninstall unwanted custom modules.
237+ - Recompute fields in case the computation of their value has changed. See also
238+ :meth: `recompute_fields `.
239+ - Uninstall unwanted custom modules. See also :meth: `remove_module `.
209240- Correct faulty data or wrong configurations.
210241
211242.. _upgrade_custom/upgraded_database/test_custom :
@@ -221,13 +252,12 @@ Things to pay attention to:
221252
222253- Views not working: During the upgrade, if a view causes issues because of its content, it gets
223254 disabled. You can find the information on disabled views on the :ref: `Upgrade report
224- <upgrade/upgrade_report>`. This view needs to be activated again. To achieve this, we recommend
225- the use of migration scripts.
255+ <upgrade/upgrade_report>`. This view needs to be activated again (or removed if not useful anymore).
256+ To achieve this, we recommend the use of upgrade scripts.
226257- :doc: `Module data <../tutorials/define_module_data >` not updated: Custom records that have the
227258 ``noupdate `` flag are not updated when upgrading the module in the new database. For the custom
228- data that needs to be updated due to changes in the new version, we recommend to use migration
229- scripts to do so.
230-
259+ data that needs to be updated due to changes in the new version, we recommend to use upgrade
260+ scripts to do so. See also: :meth: `update_record_from_xml `.
231261
232262.. _upgrade_custom/testing_rehearsal :
233263
@@ -247,7 +277,6 @@ In addition to that, make a full rehearsal of the upgrade process the day before
247277production database to avoid undesired behavior during the upgrade and to detect any issue that
248278might have occurred with the migrated data.
249279
250-
251280.. _upgrade_custom/production :
252281
253282Step 6: Production upgrade
0 commit comments