views:

86

answers:

2

I am currently trying to automate the deployment process of our rails app as much as possible, so that a clean build on the CI server can trigger an automated deployment on a test server.

But I have run into a bit of a snag with the following scenario: I have added the friendly_id gem to the application. There's a migration that creates all the necessary tables. But to fill these tables, I need to call a rake task.

Now, this rake tasks only has to be called once, so adding it to the deployment script would be overkill.

Ideally, I am looking for something like migrations, but instead of the database, it should keep track of scripts that need to be called during a deployment. Does such a beast already exist?

+1  A: 

I can't think of anything that does exactly what you want, but if you just need to be able to run tasks on remote servers in a one off fashion you could always use rake through capistrano.

There's an SO question for that here: http://stackoverflow.com/questions/312214/how-do-i-run-a-rake-task-from-capistrano, which also links to this article http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/.

Edit: I wonder if it's possible to create a migration which doesn't do any database changes, but just invokes a rake task? Rake::Task["task:name"].invoke. Worth a try?

jonnii
Sure, I use migrations to update data en-masse. No reason you have to change the db schema.
wesgarrison
Well then why not create a migration which calls a rake task which executes your one off change. That should work...
jonnii
Wow, I didn't even consider just using the migrations for this. I always equated "migration" with "database".
AGraefe
It's a bit of a hack...
jonnii
+1  A: 

I would consider that running that rake task is part of the migration to using friendly_id. Sure, you've created the tables, but you're not done yet! You still have to do some data updates before you've truly migrated.

Call the rake task from your migration. It'll update the existing data and new records will be handled by your app logic in the future.

wesgarrison