Odoo Database Neutralization

In this article, we’ll explore Odoo database neutralization, what it entails, why it matters, and best practices for implementing it.


What is Odoo Database Neutralization?


Database neutralization refers to the process of making a database environment neutral, meaning that it can be used for testing or development purposes without having any impact on the production server.


After copying a production database to a non-production environment, configuration settings (such as payment gateways, emails, and automated workflows) should be neutralized to avoid unwanted consequences, like sending emails to real customers or processing payments in testing environments. Key areas for resetting include:


Email Servers: Disable or modify email server configurations so that no emails are sent.

Payment Gateways: Replace real payment gateway configurations with test accounts or sandbox environments.

Scheduled Actions: Disable or adjust automated scheduled actions to prevent running them unnecessarily in a development environment.

Access Rights: Review and neutralize access rights to prevent unauthorized access to sensitive sections of the system.


But in case of customization, extra API connection key needs to be remove or changed. For example if you push data to an external production server using API keys, you do not want the test or development data to be pushed on the actual production server


How Odoo neutralizes the database


In Odoo.sh, to build a staging branch or when you download a backup of you  production environment, Odoo.sh will ask you if you want the production or the neutralized version of the database. 


Since v16.0 Odoo uses an SQL script which is stored in the file data/neutralize.sql if present. This SQL script allows you to tell Odoo.sh what action should be taken during the neutralization of your module.


here is an example of odoo neutralization script


-- deactivate mail servers
UPDATE ir_mail_server
SET active = false;

-- insert dummy mail server to prevent using fallback servers specified using command line
INSERT INTO ir_mail_server(name, smtp_port, smtp_host, smtp_encryption, active, smtp_authentication)
VALUES ('neutralization - disable emails', 1025, 'invalid', 'none', true, 'login');

-- deactivate crons
UPDATE ir_cron
SET active = false
WHERE id NOT IN (
SELECT res_id
FROM ir_model_data
WHERE model = 'ir.cron'
AND name = 'autovacuum_job'
);




Conclusion


When multiple developers work on a project, Odoo's standard database neutralization techniques play a crucial role in preventing critical mistakes from affecting the production environment. Side effects, such as sending thousands of test emails to clients due to development testing, are avoided, ensuring that development activities do not interfere with live business operations. Implementing a proper neutralization process fosters safe collaboration, allowing developers to work effectively without compromising the integrity or privacy of production data.

PostgreSQL table sizes