8

We just upgraded our virtual machines to what I thought was an identical ruby configuration (via RVM... Ruby 1.9.2, Rails 3.0.7, DataMapper 1.1.0). The biggest difference was that we went from MySQL 5.0 to 5.1.

For some reason, the exact same code/database.yml that was working on our old VMs now fails on our new ones at the point it tries to connect to the database.

The issue is that this YAML:

mysql_defaults: &mysql_defaults
  adapter: mysql
  encoding: UTF-8
  username: user
  password: pass
  host: localhost

development:
  <<: *mysql_defaults
  database: devdb

production:
  <<: *mysql_defaults
  database: productiondb
  host: master.db.site.com

Is just expanding to:

  "mysql_defaults" => {
    "adapter"=>"mysql",
    "encoding"=>"UTF-8",
    "username"=>"user",
    "password"=>"pass",
    "host"=>"localhost"
  },
  "development" => {
    "adapter"=>"mysql",
    "encoding"=>"UTF-8",
    "username"=>"user",
    "password"=>"pass",
    "host"=>"localhost"
  },
  "production" => {
    "adapter"=>"mysql",
    "encoding"=>"UTF-8",
    "username"=>"user",
    "password"=>"pass",
    "host"=>"localhost"
  }

Instead of:

  "mysql_defaults" => {
    "adapter"=>"mysql",
    "encoding"=>"UTF-8",
    "username"=>"user",
    "password"=>"pass",
    "host"=>"localhost"
  },
  "development" => {
    "adapter"=>"mysql",
    "encoding"=>"UTF-8",
    "username"=>"user",
    "password"=>"pass",
    "host"=>"localhost",
    "database"=>"devdb"
  },
  "production" => {
    "adapter"=>"mysql",
    "encoding"=>"UTF-8",
    "username"=>"user",
    "password"=>"pass",
    "host"=>"master.db.site.com",
    "database"=>"productiondb"
  }

Anyone experienced this before?

According to Gemfile.lock (I deleted it and ran bundle install again, just for sanity's sake), all the installed dependencies are the same (i.e. the Gemfile.lock does not diff between the old and the new setup). Nor does the database.yml.

d11wtq
  • 33,252
  • 14
  • 115
  • 186

2 Answers2

18

Psych is the new YAML parser which is presumably better but can't merge hash keys.

This should help http://pivotallabs.com/users/mkocher/blog/articles/1692-yaml-psych-and-ruby-1-9-2-p180-here-there-be-dragons

rubish
  • 10,737
  • 3
  • 41
  • 56
  • 7
    Wow, I've placed `YAML::ENGINE.yamler = 'syck'` in my application.rb and all is good. What on earth were they thinking making something the default if it's so inherently broken? Seems like they're actually removing syck entirely, yet the two are completely incompatible by the sound of it :-\ – d11wtq May 26 '11 at 15:24
  • 1
    This kind of stuff can be quite frustrating. Argh! :) – Szymon Jeż Jun 09 '11 at 13:45
  • Thanks for this, I had this same problem just now, using MongoMapper with Rails 3.2.6 and ruby 1.9.2-p180. – Chazu Jul 15 '12 at 16:30
  • 1
    This was fixed in ruby 1.9.2-p290. If you're stuck on an older patch level, you can use the psych gem. See the closed issue [here](https://github.com/tenderlove/psych/issues/8). – Jonathan Tran Sep 07 '12 at 02:41
1

Since you have done an upgrade it may be that your database permissions have messed up. Try viewing that you have the necessary permissions i.e the machine on which the code resides has privileges to connect and modify on the database machine. Looking at you database.yml it should be something like" GRANT ALL PRIVILEGES ON productionbd.* to 'user'@'<app-server-ip>' identified by 'pass';

amit_saxena
  • 6,740
  • 4
  • 45
  • 60