capistrano-db-tasks icon indicating copy to clipboard operation
capistrano-db-tasks copied to clipboard

psych syntax error on db:pull

Open jacquescrocker opened this issue 11 years ago • 2 comments

using the latest version from git: 5ecffdba5d3da0a23556056d52c56c7f6b0f4f5b

[jc@mac] cap db:pull
    triggering load callbacks
  * 2013-09-25 06:16:12 executing `production'
    triggering start callbacks for `db:pull'
  * 2013-09-25 06:16:12 executing `multistage:ensure'
  * 2013-09-25 06:16:12 executing `db:pull'
  * 2013-09-25 06:16:12 executing `db:local:sync'
local {...}
Local database: contacts
Are you sure you want to erase your local database with server database (y)es, (n)o  ? y
local {...}
  * executing "cat /u/apps/contacts/current/config/database.yml"
    servers: ["184.106.196.52"]
    [184.106.196.52] executing command
    command finished in 1098ms
/Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/psych.rb:205:in `parse': (<unknown>): did not find expected key while parsing a block mapping at line 1 column 1 (Psych::SyntaxError)
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/psych.rb:205:in `parse_stream'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/psych.rb:153:in `parse'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/psych.rb:129:in `load'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/capistrano-db-tasks-5ecffdba5d3d/lib/capistrano-db-tasks/database.rb:64:in `initialize'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/capistrano-db-tasks-5ecffdba5d3d/lib/capistrano-db-tasks/database.rb:122:in `new'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/capistrano-db-tasks-5ecffdba5d3d/lib/capistrano-db-tasks/database.rb:122:in `remote_to_local'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/capistrano-db-tasks-5ecffdba5d3d/lib/capistrano-db-tasks/dbtasks.rb:30:in `block (4 levels) in <top (required)>'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:138:in `instance_eval'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:138:in `invoke_task_directly'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.15.4/lib/capistrano/configuration/callbacks.rb:25:in `invoke_task_directly_with_callbacks'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:89:in `execute_task'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.15.4/lib/capistrano/configuration/namespaces.rb:191:in `method_missing'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.15.4/lib/capistrano/configuration/namespaces.rb:191:in `method_missing'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.15.4/lib/capistrano/configuration/namespaces.rb:110:in `block in define_task'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/capistrano-db-tasks-5ecffdba5d3d/lib/capistrano-db-tasks/dbtasks.rb:37:in `block (3 levels) in <top (required)>'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:138:in `instance_eval'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:138:in `invoke_task_directly'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.15.4/lib/capistrano/configuration/callbacks.rb:25:in `invoke_task_directly_with_callbacks'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:89:in `execute_task'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.15.4/lib/capistrano/configuration/execution.rb:101:in `find_and_execute_task'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.15.4/lib/capistrano/cli/execute.rb:46:in `block in execute_requested_actions'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.15.4/lib/capistrano/cli/execute.rb:45:in `each'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.15.4/lib/capistrano/cli/execute.rb:45:in `execute_requested_actions'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.15.4/lib/capistrano/cli/help.rb:19:in `execute_requested_actions_with_help'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.15.4/lib/capistrano/cli/execute.rb:34:in `execute!'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.15.4/lib/capistrano/cli/execute.rb:14:in `execute'
  from /Users/jc/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.15.4/bin/cap:4:in `<main>'

My database.yml has ERB in it:

app@production-20130711:~$ cat /u/apps/contacts/current/config/database.yml
<%= ENV['RAILS_ENV'] %>:
  adapter: postgresql
  encoding: unicode
  database: <%= ENV['PGDATABASE'] %>
  pool: 5
  username: <%= ENV['PGUSER'] %>
  password: <%= ENV['PGPASSWORD'] %>
  host: <%= ENV['PGHOST'] %>
  port: <%= ENV['PGPORT'] %>

jacquescrocker avatar Sep 25 '13 13:09 jacquescrocker

on inspection, I think the ERB loading (https://github.com/sgruhier/capistrano-db-tasks/blob/master/lib/capistrano-db-tasks/database.rb#L64) needs to pull in the ENV variables from the server.

Or maybe it can be executed within the scope of the project on the server side

That way things would always work as expected

jacquescrocker avatar Sep 25 '13 13:09 jacquescrocker

sort of dumb, but I got this to work:

@cap.run(%{ruby -rerb -e 'puts ERB.new(File.read("#{@cap.current_path}/config/database.yml")).result'}) do |c, s, d|
  @config += d
end

jacquescrocker avatar Sep 25 '13 13:09 jacquescrocker