What is the difference between repairing or recovering an Odoo database and upgrading an Odoo database?
The primary difference between these two activities is that in one case you are intentionally moving an Odoo database from one version of Odoo to another. In this example we are taking a database that is running on a version of Odoo that is many months old and upgrading it to the latest master build. This process breaks the database and requires multiple steps in order to remove the critical errors out of the database.
When you are repairing or recovering an Odoo database from the outset, typically it is uplanned. Perhaps a custom modification has made it impossible for Odoo to launch the server? Maybe a git pull from the latest source is conflicting with a community module or was unable to properly configure your database for the new source. While this is most often a problem when upgrading Odoo from the master branch, it is possible it can happen for a variety of reasons. Another common example is database relational integrity.
What are some of the skills I need to get value from this video?
This is an advanced Odoo topic. The associated videos listed at the bottom of this page are considered pre-requisites. Specifically it helps to understand Odoo's database architecture, the development cycle, and Odoo's overall framework.
Working through the database and finding out what is breaking
When repairing an Odoo database you will often find yourself confronted with Internal Server 500 errors when you attempt to access the Odoo instance. This very generic error gives you no information. While the video goes into the details of all the specific troubleshooting techniques, here are some of the techniques that can help you fix Odoo databases:
1. Run Odoo from the command prompt and watch the log
If you are used to just stop and starting the Odoo service and then going to look at the log this can slow your cycle. Instead, launch Odoo from the command line and get immediate feedback on the errors that are causing Odoo to fail to startup.
2. Plan to make many changes using SQL commands
Expect to use a tool like PG Admin 3 or get very comfortable with psql so that you can quickly modify the database structure, make changes to records, and do queries to get a good look at the data. The better you are at finding and fixing data and structure of the database, the faster you will fix your problem.
* Learn how to identify what needs to get fixed in an Odoo database to recover or get it working again... get familiar with the SQL queries to find and fix the problem.
3. Put print and debug statements in to help you find out what is going on in the code
As you will see in the video, you often need to know more information than just that an error occured. This is where you must add some statements to print out critical information that can help you determine what Odoo is expecting. Repairing a database often means that fields have been re-purposed or perhaps fields that were previously optional are now required.
4. When upgrading from one version of Odoo to another, or from master branches... the longer time between the builds, the more you will have to fix.
In this video you get to see first hand a migration by an Odoo expert taking Odoo Class from master branches in September 2014 build into a May 2015 master Odoo 9 build... There are very few Odoo developers with the skill Diogo shows in this video at tracking down and fixing an Odoo database. If this system also contained manufacturing, accounting & finance, purchasing, and other more ERP related applications the time required to upgrade the database would be even greater. Therefore, one strategy you can persue is to upgrade your database to builds that are closer to your existing database allowing you to do the upgrade in smaller pieces.
5. Eliminate applications and data you don't require in your upgrade
Consider when upgrading that each application and dataset you move over into new versions of Odoo has the potential to break part of the database. Therefore, if for example you have applications that can be added back in later after the upgrade, that can shave off time for your upgrade.
6. Test every process backwards and forwards. Make sure you test them again when you enable/disable any new options. Test Extensively.
Upgrading a database into a new version of Odoo has additional risks and complexities that you must consider. Even with extensive testing you may find that when you add a new application or turn on a particular feature, you expose a new bug that must be fixed. Don't just assume that because you have a working database that it is completely fixed. It is very easy to miss problems with a database that has been upgraded from a previous version of Odoo.
7. Consider importing data using XML-RPC into a fresh Odoo installation.
Depending on your specific requirements it maybe easier to import data from an older Odoo database version into a new Odoo installation rather than attempting to upgrade an older Odoo database to be compatible with the latest Odoo build.
8. Learn the skills required to fix an Odoo database before you need them for an important recovery
This video has great value for anyone who intends to install & manage Odoo systems because regardless of your practices, it is very possible that because of custom applications or even a new build within an existing Odoo stable release will break an Odoo database. Knowing how to fix these problems can be invaluable to getting a system back up and running fast. Sure you can go to a backup of a database... but often even with good backup systems this can cost a business a full day of work. If however you wait until you have a problem and then have to start learning the process of fixing a database you will likely save time just going to the backup... the learning curve is just too long to do this operation under pressure. However, knowing how to troubleshoot these Internal Server 500 errors, find relational integrity problems in your Odoo database, or fix data that is causing critical errors can be invaluable and can save countless hours of worker time.
9. For production environments, stick with stable releases and use Odoo Enterprise Services to upgrade your database when possible
Once you get several builds out the difficultly in migrating from one Odoo version to another becomes increasingly complex. If you are on a stable Odoo build and continue to patch that build it is likely with the skills you can learn from this video you can fix most any Odoo database error. If you are lucky you will never need to get in and fix a Odoo database, but in practice it is often fix the database or go to a backup. Your best defense in production environments is to always stick with stable releases... don't go for the master branch as that will have much greater volatility. This video was in fact designed to demonstrate what it really takes to handle volatility within the master branch and move a database between one version of Odoo and another. In practice, it is most likely even with this video we will create a new Odoo database from scratch and import the required data and move over the website using the tool demonstrated in the previous video. Consider this video as a learning tool in handling serious database consistency problems and a resource when you get stuck finding problems within your Odoo database.
10. Always have a solid business continuity plan in place
Despite all you can do to repair a database it is critical that you always have a plan in place to guarantee business continuity. Don't just make backups of your databases. Test those backups along with the exact backup of the Odoo build you would revert to. You should test your Odoo recovery plan immediately following any deployment or major upgrade as well as at periodic intervals. If you have gone longer than six months without testing your backup systems by doing a full test recovery for business continutity... then you have gone too long. Don't just assume you can pull what you need from a backup to get back up and going. It takes too long to configure servers, databases, connections, and get everything tested out to leave it up to chance.