Guide: Direct Server-to-Server Migration¶
The odoo-data-flow library includes a powerful migrate command designed to perform a direct, in-memory data migration from one Odoo database to another. This is an advanced feature that chains together the export, transform, and import processes into a single step, without creating intermediate CSV files.
When to use this? This method is fast and convenient for simple, one-shot migrations where you don’t need to inspect or modify the data mid-process.
For more complex, robust, and auditable migrations, we strongly recommend the File-Based Migration Workflow, which gives you much greater control and visibility.
Use Case¶
This command is ideal for scenarios such as:
Simple data transfers from a staging server to a production server.
Consolidating data from one Odoo instance into another where the data structure is identical.
The odf migrate Command¶
The migration is handled by the migrate sub-command. It works by exporting data from a source instance, applying an in-memory transformation, and then immediately importing the result into a destination instance.
Command-Line Options¶
The command is configured using a set of options that combine parameters from both the export and import commands.
Option |
Description |
|---|---|
|
Required. Path to the |
|
Required. Path to the |
|
Required. The technical name of the Odoo model you want to migrate (e.g., |
|
Optional. Path to a Python file containing a |
|
A comma-separated list of the technical field names you want to migrate. If omitted, all fields will be exported. |
|
An Odoo domain filter to select which records to export from the source instance. Defaults to |
|
The number of parallel workers to use for the export phase. Defaults to |
|
The batch size for the export phase. Defaults to |
|
The number of parallel workers to use for the import phase. Defaults to |
|
The batch size for the import phase. Defaults to |
Note on Data Integrity: The migration process automatically uses the equivalent of the
--technical-namesflag during export. This is a deliberate design choice to ensure that the migration is robust and not dependent on the languages installed in the source or destination databases.
Full Migration Example¶
Let’s say we want to migrate all partners from a staging server to a production server. We also want to add a prefix to their names during the migration.
Step 1: Create two connection files
You would have two configuration files: conf/staging.conf and conf/production.conf.
Step 2: Create a Transformer File (Optional)
If you need to transform the data, create a transformer file (e.g., partner_migrator.py):
# partner_migrator.py
import polars as pl
from odoo_data_flow.lib.transform import Processor
processor = Processor(
mapping={
"name": "[STAGING] " + pl.col("name"),
# other fields will be mapped 1-to-1 automatically
}
)
Step 3: Run the migrate command
You would run the following command from your terminal:
odf migrate \
--config-export "conf/staging.conf" \
--config-import "conf/production.conf" \
--model "res.partner" \
--fields "id,name,phone" \
--transformer-file "partner_migrator.py"
If you don’t provide a --transformer-file, the data will be migrated with a direct 1-to-1 field mapping.
Result¶
This single command will:
Connect to the staging Odoo database.
Export the
id,name, andphonefields for allres.partnerrecords.In memory, apply the transformations from
partner_migrator.py.Connect to the production Odoo database.
Import the transformed data.