Help

0

What is the Best Way to Migrate Data in a Custom Module?

Avatar
Tyler K

I am doing a migration for a custom module that involves a significant schema change (e.g., merging tables together). I exported the data from the old version module of the module, processed it to match the new schema, and am now trying to figure out how to import it. I am curious if there is a suggested best way to solving this kind of problem. Based off of my current understanding, I have the following options.

  • Import via csv.

    • I actually tried this, but ran into an issue with not being able to import readonly fields. I can get past this by making these fields editable but I like to use the readonly attribute for fields that should only be set programmatically. I suppose I could just make the fields readonly in the view and not on the model, but I would prefer to set this on the model if possible.

  • Import via module data.

    • I assume importing data this way would bypass the readonly field restriction, but I am unsure how it would handle conversions. I have a binary field that when exported as csv is Base64 encoded and am not sure if it would properly decode that data when reading it from an xml file.

  • Import via Odoo migration script.

    • Seems like this option would require installing the old version alongside the new version and mapping data from the old models to the new models, which seems a bit clumsy.

  • Import via sql script.

    • This would certainly bypass all restrictions placed by the framework, but seems a little dangerous. If my assumption is correct, when importing data via any of the above methods the ORM is used to create your database records, which means all validation and/or computed properties will be properly processed. Thus it seems like importing data should probably go through the ORM.

Avatar
Discard
1 Answer
0
Avatar
Ray Carnes (ray)
Best Answer

I would use module data.

You can copy the CSV  Base64 encoded string from the image field and use it directly in an XML file, like this:

<?xml version='1.0' encoding='UTF-8'?>
<odoo>
<record model="res.partner" id="1">
<field name="name">Odoo</field>
<field name="image_1920">iVBORw0KGgoAAAANSUhEUgAAAJYAAACWCAMAAAAL34HQAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMAUExURQAAAIdae4dcfYhae4lbfIldf4pefYpggIxhgo1igI9lhI9nhJBnhZJph5Vui5dwjJhwjZlxj5t1kZp2kJt3kZx1kp13k6F+maOAmaOCm6SCm6SCnKeIn6mHn62Npa2PpK6Ppa+Rp7KWq7OWrLWarbearrecr7qhs72jt76kt7+nub+ousCou8Cqu8GqvAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHtU8wYAAAEAdFJOU////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////wBT9wclAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGHRFWHRTb2Z0d2FyZQBwYWludC5uZXQgNC4xLjb9TgnoAAAFMElEQVR4Xs2c6ULqMBCFe0HcUNwBtSooiPv7v503bU+lLZnMpE3b+X4VnJwcS5s9iX6bs1o+zKeT8Wg0nkznD8sVvm5CI1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jGFPFSCA3mCSTTGFQFUggN5gnHEtKyhEhzIE4y02lL6Iyp95JUWEHNcEUAlOJAnmEcPuCKASnAgT/AQMdNi/VTVS60NG+Z29tUMZGwpbTS39MxDnMLYUtoh66P7yixHSLqvSjv7SodGuJieBpI4Wy3cLgiTpLY47z0NUiod0mXvaT8D4KytnqYLlE6uKJuKStZoJLb4yF4m7gRb+5KoMECQZjvNycf2MimsdQpd6YID/lfsZXmG1sUskhQ9LP3RulBK6bIypYvwtC5ZbHWBJ1+KplgWeIpexoSOl8NqXTwsvV2GLpdaa12YrnQZv8/PmNDVpgf/TdTX1BYR8XOeU95qXbaldEON1u1HfW3Wqm7+rtpSurVN60ZArdsmtW4yFTYkQ2Ft8lpteZb2zUCWZey2lG73Vro53tBJcU92pUhbXbyPdMeTtqX0mAqth3poPQLFtCdae/CH1Q3eZdy2lB6vY/Deai2hvInaAmurhTfS8QbmCGwpPejKoPJYsASVh6gZdB45Z1B5QF9Kg1KMK6nK+NlSevhjisajMlNUHiyasRYM0551ewxrjsJDawusFvEsP+J3Fi+aH/H7+/sfvHHUffPHK6UAAAAASUVORK5CYII=</field>
</record>
</odoo>
This imports a Contact like this:


Avatar
Discard