In my environment, the application logins do not have the ability to
alter the schema to create tables, etc. There is a separate schema
owner account with that capability. So I cannot run "rake migrate"
using the database.yml configuration. Is there a way to run migrations
with a different account?
There isn't any magical way to do more than the permissions you have allow you to do, if that's what you're asking. If you have a different db user account that has sufficient permissions, then just plug it into the database.yml file.
Let me be more specific. My rails app is not allowed to use the schema
owner account, so I cannot just put it in the database.yml file. In
addition, I cannot leave the password for that account on the
filesystem. So even if there was a way to select a different
database.yml file for the migrations only, I cannot do that. (Although
I'd still be interested to know if there's a way to select a different
database.yml on the fly).
What would be ideal: a front end to rake db:migrate that asks me for
the username/password to the account, and overrides the database.yml
entries for them. Is there a way to do this via a new rake task? Or
maybe it would be easier to modify the existing db:migrate task?
Nope, it is as I thought--you can't put ERB into database.yml.
I'm going down the path of trying a custom rake task, but I have no
idea where database.yml exists as a variable after it has been loaded
by Rails. Does anyone know?
well I haven't bothered to go any further back than revision 2115,
but ERB parsing of database.yml has been in rails trunk since at least
September 2005, maybe before then even.
Well then I apologize. My quick test didn't work and I guess I jumped
to the conclusion.
> and equally;
> ActiveRecord::Base.configurations is the hash of the database
> connections.
Thanks!
and I think this rake task will do what you want also
desc "run your migration as db root"
task "db:migrate_as_root" do
original_config = ActiveRecord::Base.configurations[RAILS_ENV ||
"development"]
config = original_config.merge(ROOT_USER_PASS_HASH)
ActiveRecord::Base.establish_connection(config)
Rake::Task["db:migrate"].invoke
end
Yes! This is very close to what I need. I'll take it from here. Thank
you very much!
well I haven't bothered to go any further back than revision 2115,
but ERB parsing of database.yml has been in rails trunk since at least
September 2005, maybe before then even.
Well then I apologize. My quick test didn't work and I guess I jumped
to the conclusion.
> and equally;
> ActiveRecord::Base.configurations is the hash of the database
> connections.