Thanks,
- Mark.
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.
--
Greg Donald
Cyberfusion Consulting
http://cyberfusionconsulting.com/
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?
how about this solution;
database.yml
============
<%
def as_db_admin?
defined?(AS_DB_ADMIN) && AS_DB_ADMIN == "true"
end
%>
production:
adapter: mysql
database: databasename
host: localhost
username: <%= as_db_admin? ? "root" : "normal" %>
password: <%= as_db_admin? ? "root" : "normal" %>
============
"rake db:migrate AS_DB_ADMIN=true"
I belive that'll set the global constant AS_DB_ADMIN,
and hence do what you want.
Otherwise it sets ENV["AS_DB_ADMIN"]
but I think it actually sets the constant directly.
Give it a try.
--
Posted via http://www.ruby-forum.com/.
yeah.
it's not obvious, until you look at the code.
I use it all the time, so I can do host specific databases
(namely I have 3 different environments I want to run the tests on, some
of them have the database running on localhost, but the others have
dedicated db servers with different names)
it works proper fine.
<%
def sharon_or_localhost
if ["punky", "munky"].include? Socket.gethostname
return "sharon"
else
return "localhost"
end
end
%>
test:
adapter: mysql
database: testdb
username: test_user
password: th1si5aTESt
host: <%= sharon_or_localhost %>
# Loads and returns the contents of the #database_configuration_file.
The
# contents of the file are processed via ERB before being sent through
# YAML::load.
def database_configuration
YAML::load(ERB.new(IO.read(database_configuration_file)).result)
end
see railties/lib/initializer.rb -- don't know which line.
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?
hmm...
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.
and equally;
ActiveRecord::Base.configurations is the hash of the database
connections.
and I think this rake task will do what you want also
================
/lib/tasks/migrate_as_root.rake
================
ROOT_USER_PASS_HASH = {"username" => "root", "password" => "rootpass"}
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
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
>
> ================
> /lib/tasks/migrate_as_root.rake
> ================
>
> ROOT_USER_PASS_HASH = {"username" => "root", "password" => "rootpass"}
>
> 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!
- Mark.
Yeah, no wuzz...
I don't like being wrong.
Take it easy....
btw, do you happen to know of Mark Thomas the english
comedian/activist... he's pretty darn cool.