Skip to content

Commit

Permalink
Run db:schema:load when deploying with COLD=1
Browse files Browse the repository at this point in the history
This needed when deploying to a server for the first time or when you
want to wipe out a database.

The issue I'm fixing is this. Things have evolved and in
https://github.com/coopdevs/timeoverflow-provisioning we no longer set
things up to enable PostgreSQL extensions such as `pg_trgm`. Because
Capistrano runs `db:migrate` when deploying very old migrations
like `db/migrate/00000000000002_setup_pg_trgm.rb` don't work anymore.

I prefer to make this step explicit in the code and with some context
rather than having to do this manually in the server and let the dev in
charge figure it out every time.

Apparently, from capistrano/rails#118 I see
this is a known issue for which there's no provided solution. I copied
a solution proposed by a capistrano/rails member so should be good.

Just run it as follows:

```
$ bundle exec cap staging deploy COLD=1
```
  • Loading branch information
sauloperez committed Nov 20, 2019
1 parent 268bc0d commit 05dcbdc
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,14 @@
end
end
end

task "deploy:db:load" do
on primary :db do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, "db:schema:load"
end
end
end
end
before "deploy:migrate", "deploy:db:load" if ENV["COLD"]

0 comments on commit 05dcbdc

Please sign in to comment.