Monthly Archives: May 2014

Ruby and YAML for database table and column remapping

I’m working on converting an infrastructure inventory application from Rails 3 to 4 but since this was one of my early Rails app (written several years ago) I thought I’d take the opportunity to straighten a few pieces out:

  • implement the authentication and activity logging scheme I’ve recently developed for my Rails 4apps,
  • Make the table column names more consistent. For example, instead of description, notes or details, just have description,
  • Remove superfluous created_by and updated_by columns which are covered by the activity_log.

Now, this will involve a serious amount of data porting (hundreds of hosts, application and databases and supporting details in roughly 60 tables) and I really didn’t fancy editing a large mysqldump file so I decided to write a script.

For no particular reason I decided to use YAML to describe the tables, the columns to read and write to as well as allowing different source and target table and column names. As it turned out not a bad choice.

It’s taken me a day to write the script (and it is particularly ugly even by my standards) but it will save several days worth of effort doing the migration and it will of course allow the process to be done repeatedly.

Although it is a horrible script, I’m likely to post it on my GitHub page for future reference and because I might try and clean it up sometime.

Advertisements