1

I m trying to use Datamapper as ORM for my Ruby/Padrino application. To setup db connection, in databse.rb, I have:

when :development then DataMapper.setup(:default, "mysql://db_user:dsfsdfs@localhost/my_app_development")

This work fine. But my requirement is to have complex password, something like:

when :development then DataMapper.setup(:default, "mysql://db_user:Passw0rd#13@localhost/my_app_development")

This doesn't work and I get error:

ruby/1.9.1/gems/addressable-2.2.8/lib/addressable/uri.rb:1179:in `port=': Invalid port number: "Passw0rd" (Addressable::URI::InvalidURIError)

I figured out that the '#' character is problem. Then I attempted doing this:

DataMapper.setup(:default, 
{
    :adapter => "mysql",
    :database => "my_app_development",
    :username => "db_user",
    :password => "Passw0rd#13",
    :host => "localhost"
})

When I do this, it seems like DM is ignoring the hash altogether; when I run

padrino rake db:create

It tries to connect as current logged in user, rather than the username specified here. Solution?

constantine1
  • 427
  • 1
  • 5
  • 12

2 Answers2

0

I suppose you still need to have to declare it like following, in case you are not

when :development then
  DataMapper.setup(:default, 
  {
      :adapter => "mysql",
      :database => "my_app_development",
      :username => "db_user",
      :password => "Passw0rd#13",
      :host => "localhost"
  })
when :production then
  # rest of your code
end
ch4nd4n
  • 4,110
  • 2
  • 21
  • 43
  • Exactly what I am doing....I just replace the string with hash. Server is able to connect to DB with hash, its only the migration which isn't running. Seems like a bug in dm-migrations. – constantine1 Jan 23 '13 at 09:53
0

Got it - the key :username should be :user. Basically, the hash should contains keys as understood by Addressable::URI

constantine1
  • 427
  • 1
  • 5
  • 12