I am in the process of packaging a rails application as an RPM, and I
have a few questions regarding the initialization of the database
As part of the post-install script, I need to check to see if the
database exists. Depending on the outcome, I may have to run various
combinations of db:setup, db:migrate, and/or db:seed. Is there a rake
(or some other) task I can run to check for the existence of the
“production” database? If not, is there a “standard” way to fetch the
database name for the production environment from the database.yml
file so I can use external tools?
What I’m thinking about doing is defining the default user, password,
and database name as macros/constants in my .spec file. When I build
my RPM, I will use sed to generate database.yml with these pre-defined
values so they are consistent between my initialization scripts (in
the spec file) and the database configuration included in the
package. This would work perfectly with a new installation.
The problem with this approach is with upgrading an existing
installation. Since database.yml is a configuration file, I have to
assume that the database.yml file has been modified and that my
“defaults” no longer match the production values. I need a simple way
to ask rails “does my production database exist?”.