Home › Curriculum › Deploy, Operate & Upgrade › Migrating custom modules to a new version
Upgrades and migrations · 16 min · 17–20Migrating custom modules to a new version
Porting code and views, migration scripts (pre, post, end), version bumps, data fixes and testing.
In this lesson
- Porting code and views
- Migration scripts: pre, post, end
- Repeatable data fixes and verification
Key points
- New branch, manifest version, deps; API, view, QWeb, JS and icon changes
- Use OCA migration guides per version
- migrations/<ver>/pre|post|end-*.py with migrate(cr, version)
- Repeatable, tested on real data; compare old vs new
Real-world example
Renaming a field from x_region to region_id (Many2one) lost all values in the first test upgrade. A pre-migration script copying the old column to a temporary column, and a post-migration script mapping the text values to new region records, preserved 12,000 values and ran identically in production.
Questions and answers
Where do migration scripts live?
migrations/<module version>/ in the module.
Why not use the ORM in pre-scripts?
Models for the new version aren't loaded yet.