Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database.yml block for describing the user you want to create databases as. #1802

Conversation

cmeiklejohn
Copy link
Contributor

Allow the user to define a schema config block in databases.yml with the username and password that should be used to create the databases.

Before I clean up the commit and cut down on the code duplication, I wanted to get thoughts on the overall approach. Basically, I'm running into the situation where my connection user for a particular database configuration won't have the ability to create the database, and I want a way to define a configuration in config/databases.yml that will be used only to create the database and grant the permissions. The current problem with the root user fallback is that in many cases, I won't have an interactive terminal when calling the db:create task. I also don't want to put the root credentials into the configuration.

This change allows me to define a schema block, with a username and password that will be used as a fallback if the connection user does not have permissions to create the database.

…the username and password that should be used to create the databases.
@cmeiklejohn
Copy link
Contributor Author

@tenderlove Would love to hear your input on this...

@tenderlove
Copy link
Member

Ya. I see the problem. I'm not sure what to do though. You would have the database creation problem essentially just once, right? I'm not sure this is a large enough use case to warrant adding support to rails itself.

Maybe it would be better to hook in to the db:create rake task? For example, add a rake task to your rails application that changes the rails environment, but only on database create:

task 'muck_with_env' do
  Rails.env = 'create_database'
end

task 'db:create' => 'muck_with_env'

Then adjust your yaml file accordingly:


production:
  adapter: mysql
  database: omg_development
  user: aaron
  password: omg

create_database:
  adapter: mysql
  database: omg_development
  user: root
  password: zomg

@arunagw
Copy link
Member

arunagw commented Jan 8, 2012

@cmeiklejohn Can you please see if it still required ?? Or this can be closed? There are some code changes already. Can you please confirm.

Thanks

@cmeiklejohn
Copy link
Contributor Author

No, I think we're good. Thanks for checking in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants