bigpotato
bigpotato

Reputation: 27507

Rails: Postgres + rake db:structure:dump using wrong user

I'm trying to dump the structure of my remote database using rake's rake db:structure:dump, but whenever I run that command it ignores the user in my database.yml file and uses the user on my local machine that I'm logged in as.

Database.yml:

 development: &DEFAULT
  adapter: postgresql
  host: remoteaddress.com
  port: 5432
  user: myusername
  password: mypassword
  database: mydatabase

This is what happens when I run the command:

[~/src/myapp]$ RAILS_ENV=development rbbe rake db:structure:dump --trace                                                                                                                                                                          ✭ git:em-redshift ruby:2.2.0
** Invoke db:structure:dump (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:structure:dump
pg_dump: [archiver (db)] connection to database "mydatabase" failed: FATAL:  password authentication failed for user "emai"
FATAL:  password authentication failed for user "emai"
rake aborted!
Error dumping database
/opt/rubies/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/postgresql_database_tasks.rb:55:in `structure_dump'
/opt/rubies/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:182:in `structure_dump'
/opt/rubies/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:276:in `block (3 levels) in <top (required)>'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/opt/rubies/2.2.0/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/opt/boxen/rbenv/versions/2.2.0/bin/rake:33:in `<main>'
Tasks: TOP => db:structure:dump

As you can see, it doesn't use myusername as the user. Instead it runs it as my local user (emai). What is going on?

P.S. I know the db config works too, because I went into the rails console and queried for records and got results. Also, rake db:schema:dump works with no authentication errors.

Upvotes: 3

Views: 1210

Answers (2)

Anton Orel
Anton Orel

Reputation: 576

Jsut replace user with username.

Upvotes: 0

bigpotato
bigpotato

Reputation: 27507

After looking into the docs (https://github.com/rails/rails/blob/master/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb), you need to add a username key to get it to work... seriously...

 development: &DEFAULT
  adapter: postgresql
  host: remoteaddress.com
  port: 5432
  user: myusername
  username: myusername <-------
  password: mypassword
  database: mydatabase

Upvotes: 8

Related Questions