More on Migrations

So wanted to post a follow up on the situation I was discussing yesterday with migrations.  I’ve found a simple verbose workaround of sorts.

I’m taking one app in a django project and pushing different areas of responsibility into different apps.  For example, in khanfu people and events are being managed under the same app.  I’m pushing people data models into their own separate app and need to transfer existing data from the one app tables to the other.

To do this, first I copied over the relevant model classes into the new app and ran a schema migration using south.  In order to get the data from the big app to the people app, I decided to write a data migration vs some raw sql.  After some twists and turns around foreign keys and many relation managers, I’ve gotten the data into the new tables. Then I made the change to the old app’s models such that those old tables would be dropped in the migration.

After running through the migration correctly once, I dumped the new state of the db and attempted to refresh a new copy of the db with the data.  By running the migrate command from south, it choked because the model file for the old app could not be use.  Originally, I expected south to just silently fail here but that didn’t happen.

After much meandering and tom foolery, I figured out a work around for the moment to allow me to check in the data migration file and make sure it when migrations are run that it doesn’t break my workflow.  I’ve written a script (after a fashion, really it’s a fabfile) to run the migrations manually in a particular order, including running the data migration as a fake.  This gives me two benefits:

  • Allows me to check in the data migration, meaning I get history for work that was done on the model file.
  • Makes sure I don’t break the workflow of folks I’m working with.  The only caveat here being that I need to make sure to communicate the workflow to the team.

I’m still digging for a good workflow alternative that doesn’t require me to manually manage the migrations (via a script), but nothing’s come up yet.

  1. No trackbacks yet.

Leave a comment