This project is read-only.

Data Migration: proper way to update existing data

Topics: Administration, Core, General
Sep 17, 2014 at 10:01 AM
Hi everyone,

I have run into troubles of updating existing data with new database table schema and content type structures recently. Let me explain it by example bellow:

I have 2 methods UpdateFrom1 and UpdateFrom2 in my migration file:
  • UpdateFrom1: use to change some structure of model, like insert new column or attach new parts, fields to content type.
  • UpdateFrom2: use to correct existing data like copy value from a column to another, or copy part property value to new attached field.
Problem happen when I run 2 those methods at the same time, in UpdateFrom2 when I retrieve new attached field of content item to assign a value, new fields are not exist in my content item. Look into DataMigrationManager class, I see that Orchard run all methods of a migration in 1 transaction that's why I could not retrieve new attached fields until migration completed without error, but unfortunately in my case it throw error in UpdateFrom2 and rollback the whole transaction.

I think using migration to update existing data is not a proper way, so I hope that I can have some advice from Orchard's developer.

Can you guys show me a good way to update data? or is there a convention that Orchard recommend?

Thank you very much
Oct 1, 2014 at 11:48 PM
What we do to update / migrate data is to provide a module called Upgrade. When enabled, the user can manually execute upgrade actions.
We use data migrations to upgrade structure, and use the Upgrade feature to migrate data.
Marked as answer by dungdang on 10/2/2014 at 1:33 AM
Oct 2, 2014 at 9:33 AM
Thanks for you input, my colleges and I have discussed about this solution and we were agree to create upgrade module. This module depend on all our modules to handle upgrade data. Your answer is a corroboration for us :)