0

I am trying to deploy my rails app using capistrano but after db:migrate I get

  01 $HOME/.rbenv/bin/rbenv exec bundle exec rake db:migrate
  01 rake aborted!
  01 KeyError: Cannot load database configuration:
  01 key not found: "APP_DATABASE_PASSWORD"
  01 (erb):54:in `fetch'
  01 (erb):54:in `<main>'
  01 /home/deploy/app/shared/bundle/ruby/2.6.0/gems/railties-6.0.2.1/lib/rails/application/configuration.rb:228:in `database_configuration'
  01 /home/deploy/app/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/railtie.rb:39:in `block (3 levels) in <class:Railti…
  01 /home/deploy/app/shared/bundle/ruby/2.6.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
  01 /home/deploy/.rbenv/versions/2.6.3/bin/bundle:23:in `load'
  01 /home/deploy/.rbenv/versions/2.6.3/bin/bundle:23:in `<main>'

However I already have APP_DATABASE_PASSWORD set in my .bashrc file and already sourced it.

Here is my database.yml:

default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: <%= ENV.fetch("APP_DATABASE_USERNAME") %>
  password: <%= ENV.fetch("APP_DATABASE_PASSWORD") %>
  socket: /var/run/mysqld/mysqld.sock

development:
  <<: *default
  database: app_development

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: app_test

production:
  <<: *default
  database: app_production
  username: app
  password: <%= ENV.fetch("APP_DATABASE_PASSWORD") %>

In my .bashrc:

export APP_DATABASE_PASSWORD="SOME_PASSWORD"
export APP_DATABASE_USERNAME="SOME_USERNAME"
Burak Kaymakci
  • 662
  • 2
  • 16
  • 36

1 Answers1

0

in your .bashrc, if you see this line;

[ -z "$PS1" ] && return

put your export above this.

Fernand
  • 1,293
  • 1
  • 10
  • 18
  • I do not have that line in my `.bashrc`. Just something like this `PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"` – Burak Kaymakci Feb 23 '20 at 08:04
  • But I had `case $- in *i*) ;; *) return;; esac` pasting above that block fixed as mentioned in [this answer](https://stackoverflow.com/a/48703295/4796762) – Burak Kaymakci Feb 23 '20 at 08:26