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

Be more explicit about the default of db:drop and db:create #13629

Merged
merged 1 commit into from Jan 8, 2014
Merged

Be more explicit about the default of db:drop and db:create #13629

merged 1 commit into from Jan 8, 2014

Conversation

dmathieu
Copy link
Contributor

@dmathieu dmathieu commented Jan 8, 2014

Closes #13625

@prathamesh-sonpatki
Copy link
Member

@dmathieu Can also add this to create task right? rake db:create also creates development and test databases by default right?

@dmathieu
Copy link
Contributor Author

dmathieu commented Jan 8, 2014

You're right. Thank you. 🌞

@@ -12,7 +12,7 @@ db_namespace = namespace :db do
end
end

desc 'Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:create:all to create all databases in the config)'
desc 'Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:create:all to create all databases in the config). Defaults to creating the development and test databases'
task :create => [:load_config] do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmathieu I think it can be better worded by
Defaults to creating the development and test databases in absence of Rails.env

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There never is an absence of Rails.env. It defaults to development.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Yes you are right :)

@prathamesh-sonpatki
Copy link
Member

@dmathieu Will it work with [ci skip] ?

@senny
Copy link
Member

senny commented Jan 8, 2014

From the description it's not obvious to me, when the default applies and how I can change it to only create the database of the current Rails.env.

@senny
Copy link
Member

senny commented Jan 8, 2014

Looking closer I think we should also change the functionality. Currently:

  • bin/rake db:create => creates dev and test
  • RAILS_ENV=development bin/rake db:create => creates dev and test
  • RAILS_ENV=test bin/rake db:create => creates test

I think if the RAILS_ENV is specified it should only create the database for that env. This would also allow us to reword the description to:

Create the database from DATABASE_URL or config/database.yml 
for the current RAILS_ENV (use db:create:all to create all databases in the config). 
Without RAILS_ENV it defaults to creating the development and test databases.

This explains when the default is active and how it can be changed.

@senny
Copy link
Member

senny commented Jan 8, 2014

This is even worse when using db:drop. For example:

RAILS_ENV=development bin/rake db:drop will also drop your test database.

@dmathieu
Copy link
Contributor Author

dmathieu commented Jan 8, 2014

@senny: your idea definitely makes sense.
I just pushed it.

@@ -201,7 +201,7 @@ def class_for_adapter(adapter)

def each_current_configuration(environment)
environments = [environment]
environments << 'test' if environment == 'development'
environments << 'test' if environment == 'development' && ENV['RAILS_ENV'].nil?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is quite hidden. Let's at least add a comment why that check is there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

senny added a commit that referenced this pull request Jan 8, 2014
Be more explicit about the default of db:drop and db:create
@senny senny merged commit b502e3d into rails:master Jan 8, 2014
@senny
Copy link
Member

senny commented Jan 8, 2014

@dmathieu thanks 💛

@dmathieu dmathieu deleted the drop_test branch January 8, 2014 13:39
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.

rake description for db:drop needs to be updated to mention that it drops both development and test database
3 participants