开发者

Migrating several legacy databases into one Rails app

I have several (old) Drupal-sites that need to be replaced with one single new Rails app. That new site should hold all old Drupal-content. That old Drupal-content is partly broken (due to nearly 7 years of fugly upgrades, discontinued modules and so on). The fact that it is Drupal is hardly relevant, just the fact that it causes some inconsistencies, weird naming, and badly normalised tables.

The content needing to be imported into the Rails app is simple: content (blog-entries), attached files (images) and comments. I have the luxury of two databases being "stale" (not in production) and two more being in production, but allowed to go down/locked for a while (hours, days). So, the migrations need not be optimized for spee开发者_高级运维d, or be entirely save (meaning: I can afford to loose a comment being posted while running the migration)

The Rails(3) app is mostly done, and using Active-record conventions only.

Due to the contraints (broken, inconsistent database, several databases needing merging) I prefer to write migrations for this, instead of connecting my new Rails app to an ugly, inconsistent legacy databse.

My questions are:

  • Are there any environments, gems or tools that make importing in Rails easier: e.g. something that allows simple mapping from old-new in some DSL.
  • Or is it easier to write my migrations entirely in SQL: SQL queries that will turn the old data into the structure that fits the Rails app? Migrating is from MySQL->MySQL.
  • Or should I just connect Activerecord to the old databases, loop over each row/result and run an Object.save! in my rails app?


Interesting case, I am facing the same issue on my current project.

I think you should consider the second point!

Or is it easier to write my migrations entirely in SQL: SQL queries that will turn the old data into the structure that fits the Rails app? Migrating is from MySQL->MySQL.

Write the SQL migrations to import the data from your old database to the new one, then work with the new schema! I suppose you have a dump SQL file with a list of INSERT queries for each old-database.

So the strategy for this could be:

  1. Create one SQL view for each table of the old database schema, from your new schema.
  2. Run those INSERT against your views.

At first, I was going to tell you about the legacy_data gem which basically generates all the model layer with the appropriate validations/associations, but it is useless in your case given that you already have all the necessary models set up in your Rails application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜