DRY up mysql/postgres yaml generators

Hey folks,

Not sure about you, but when setting up a rails project, I get tired of
specifying username, login, etc 3 times, when it should only be done
once, in the config/database.yml file.

To me, it makes more sense to use yaml and do the following:

login: &login
  adapter: mysql
  encoding: utf8
  username: robert
  password: super_secret

  database: cool_app_development
  <<: *login

  database: cool_app_test
  <<: *login

  database: cool_app_production
  <<: *login

So, I've written a patch for mysql and postgres generators to follow the
above, instead of what we are used to. Links below, looking for some
+1's :slight_smile:

link: http://dev.rubyonrails.org/ticket/10069

I use it, but have noticed that a significant number of coders don’t like this YAML feature.

Please, express your opinions here.

The syntax is too obscure and not many people know it. It could
confuse people who use Rails for the first time, or people who are not
intimately familiar with YAML. I think it's more important that the
config file is easy to read, than saving 20 seconds at the beginning
of a project.

I agree. Perhaps it could just be a link in the comments of
database.yml which points to more info on the rails rdoc/trac?

-- Chad

Yes, that's a good compromise.

How about keeping the structure I suggested, but adding comments
explaining the structure for clarification? To me it makes sense
because it DRY's up your code, something Rails advocates, but doesn't
follow in this area.

Yes but Rails also advocates readability, and unfortunately this YAML
syntax doesn't. I think readability is more important.

Agree. Too much DRY leads to perlism sometimes, this is quite close to
that. And not much to gain from it either.

I rarely use the same username and password for my production and
development databases, so not only does this obfuscate the file a
little bit it also makes me have to do more work when I get ready to
do production testing and deployment.


I totally disagree with the "perlism" comparison here. If it is a
taste thing, that's understandable, but saying the above code snippet
is too hard to read or akin to perlism, I don't agree. But whatever
the consensus is, is cool with me.

Second. I actually use Robert's syntax myself, as I'm sure many developers
do, but it would be too daunting for a first-time configuration.

Now, if there were a way to specify "default:" at the top, and have the
*code* that reads database.yml merge in the default hash keys, that would
be more worthwhile. But -1 for the pure-YAML version.