Search code examples
ruby-on-railscapistrano

Capistrano 3 database migrations fail and does not create current symlink


I've never worked with Capistrano before and currently I am fighting the urge to just scrap it and go back to my old manual ways.

As I understand, Capistrano V3 does not create the initial database because they feel it is the duty of the DB administrator.

So I must be missing something but I have followed their instructions but the initial cap staging deploy fails when it gets to the rake db:migrate step because the database does not exist.

Because of the failure, the symlink for current -> releases never gets created.

Is it just accepted general practice that we SSH into our boxes and cd into the first folder under releases and manually run rake db:create...?

And then from there, am I supposed to just run cap staging deploy again so that it finishes creating the symlinks?

Seems hacky for something that is supposed to make things easier and I am not sure if I am understanding this correctly or not.

Thanks.


Solution

  • It does make sense to leave certain things out of a deployment. As the initial set up and the routine deployments are very separate functions and require different specialties, or in large deployments even different skillsets. That said.. I'm totally with you - on the first deploy having to manually set up the database and certain files (specifically linked files like secrets.yml) is a step that just wastes my time.

    I use this plugin: https://github.com/capistrano-plugins/capistrano-postgresql

    just add the require capistrano/postgresql to your capfile as you would any plugin

    then run cap staging setup before the first time you run cap staging deploy