AGraefe
AGraefe

Reputation: 137

How to handle one-off deployment tasks with capistrano?

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?

Upvotes: 6

Views: 1137

Answers (3)

cryo28
cryo28

Reputation: 1127

Looks like after_party gem does exactly what you want.

Upvotes: 3

wesgarrison
wesgarrison

Reputation: 7105

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.

Upvotes: 1

jonnii
jonnii

Reputation: 28312

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: 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?

Upvotes: 1

Related Questions