stevo999999
stevo999999

Reputation: 608

capistrano backup db before migration

I know how to backup my db using capistrano scripts.

    before 'deploy:migration', 'db:backup'

However, backing up the database takes a long time and I really only want to do this when deployment includes a migration. Otherwise, I rather do the deployment without the backup.

Upvotes: 0

Views: 476

Answers (1)

Matouš Borák
Matouš Borák

Reputation: 15954

You can use ActiveRecord::Migrator.needs_migration? to find out whether there is a migration pending or not. However, I think that you cannot put this check directly in a capistrano task.

I would create a rake task that would run the DB backup but only if there are pending migrations (i.e. if needs_migration? is true).

Then I would create a capistrano task that would simply call the rake task before the deploy:migration task during deployment.

Upvotes: 1

Related Questions