Skip to content

Commit c8bfd68

Browse files
Merge pull request rails#50799 from jonathanhefner/command-fix-task-list-when-no-default-task
Fix `bin/rails -T` when no default task is defined
2 parents 36cc7c5 + f21e429 commit c8bfd68

File tree

3 files changed

+35
-31
lines changed

3 files changed

+35
-31
lines changed

guides/source/active_record_multiple_databases.md

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -160,39 +160,41 @@ multiply the number of connections you have since Rails uses the model class nam
160160
connection specification name.
161161

162162
Now that we have the `database.yml` and the new model set up, it's time to create the databases.
163-
Rails 6.0 ships with all the rails tasks you need to use multiple databases in Rails.
163+
Rails ships with all the commands you need to use multiple databases.
164164

165-
You can run `bin/rails -T` to see all the commands you're able to run. You should see the following:
165+
You can run `bin/rails --help` to see all the commands you're able to run. You should see the following:
166166

167167
```bash
168-
$ bin/rails -T
169-
bin/rails db:create # Create the database from DATABASE_URL or config/database.yml for the ...
170-
bin/rails db:create:animals # Create animals database for current environment
171-
bin/rails db:create:primary # Create primary database for current environment
172-
bin/rails db:drop # Drop the database from DATABASE_URL or config/database.yml for the cu...
173-
bin/rails db:drop:animals # Drop animals database for current environment
174-
bin/rails db:drop:primary # Drop primary database for current environment
175-
bin/rails db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)
176-
bin/rails db:migrate:animals # Migrate animals database for current environment
177-
bin/rails db:migrate:primary # Migrate primary database for current environment
178-
bin/rails db:migrate:status # Display status of migrations
179-
bin/rails db:migrate:status:animals # Display status of migrations for animals database
180-
bin/rails db:migrate:status:primary # Display status of migrations for primary database
181-
bin/rails db:reset # Drop and recreates all databases from their schema for the current environment and loads the seeds
182-
bin/rails db:reset:animals # Drop and recreates the animals database from its schema for the current environment and loads the seeds
183-
bin/rails db:reset:primary # Drop and recreates the primary database from its schema for the current environment and loads the seeds
184-
bin/rails db:rollback # Roll the schema back to the previous version (specify steps w/ STEP=n)
185-
bin/rails db:rollback:animals # Rollback animals database for current environment (specify steps w/ STEP=n)
186-
bin/rails db:rollback:primary # Rollback primary database for current environment (specify steps w/ STEP=n)
187-
bin/rails db:schema:dump # Create a database schema file (either db/schema.rb or db/structure.sql ...
188-
bin/rails db:schema:dump:animals # Create a database schema file (either db/schema.rb or db/structure.sql ...
189-
bin/rails db:schema:dump:primary # Create a db/schema.rb file that is portable against any DB supported ...
190-
bin/rails db:schema:load # Load a database schema file (either db/schema.rb or db/structure.sql ...
191-
bin/rails db:schema:load:animals # Load a database schema file (either db/schema.rb or db/structure.sql ...
192-
bin/rails db:schema:load:primary # Load a database schema file (either db/schema.rb or db/structure.sql ...
193-
bin/rails db:setup # Create all databases, loads all schemas, and initializes with the seed data (use db:reset to also drop all databases first)
194-
bin/rails db:setup:animals # Create the animals database, loads the schema, and initializes with the seed data (use db:reset:animals to also drop the database first)
195-
bin/rails db:setup:primary # Create the primary database, loads the schema, and initializes with the seed data (use db:reset:primary to also drop the database first)
168+
$ bin/rails --help
169+
...
170+
db:create # Create the database from DATABASE_URL or config/database.yml for the ...
171+
db:create:animals # Create animals database for current environment
172+
db:create:primary # Create primary database for current environment
173+
db:drop # Drop the database from DATABASE_URL or config/database.yml for the cu...
174+
db:drop:animals # Drop animals database for current environment
175+
db:drop:primary # Drop primary database for current environment
176+
db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)
177+
db:migrate:animals # Migrate animals database for current environment
178+
db:migrate:primary # Migrate primary database for current environment
179+
db:migrate:status # Display status of migrations
180+
db:migrate:status:animals # Display status of migrations for animals database
181+
db:migrate:status:primary # Display status of migrations for primary database
182+
db:reset # Drop and recreates all databases from their schema for the current environment and loads the seeds
183+
db:reset:animals # Drop and recreates the animals database from its schema for the current environment and loads the seeds
184+
db:reset:primary # Drop and recreates the primary database from its schema for the current environment and loads the seeds
185+
db:rollback # Roll the schema back to the previous version (specify steps w/ STEP=n)
186+
db:rollback:animals # Rollback animals database for current environment (specify steps w/ STEP=n)
187+
db:rollback:primary # Rollback primary database for current environment (specify steps w/ STEP=n)
188+
db:schema:dump # Create a database schema file (either db/schema.rb or db/structure.sql ...
189+
db:schema:dump:animals # Create a database schema file (either db/schema.rb or db/structure.sql ...
190+
db:schema:dump:primary # Create a db/schema.rb file that is portable against any DB supported ...
191+
db:schema:load # Load a database schema file (either db/schema.rb or db/structure.sql ...
192+
db:schema:load:animals # Load a database schema file (either db/schema.rb or db/structure.sql ...
193+
db:schema:load:primary # Load a database schema file (either db/schema.rb or db/structure.sql ...
194+
db:setup # Create all databases, loads all schemas, and initializes with the seed data (use db:reset to also drop all databases first)
195+
db:setup:animals # Create the animals database, loads the schema, and initializes with the seed data (use db:reset:animals to also drop the database first)
196+
db:setup:primary # Create the primary database, loads the schema, and initializes with the seed data (use db:reset:primary to also drop the database first)
197+
...
196198
```
197199

198200
Running a command like `bin/rails db:create` will create both the primary and animals databases.

railties/lib/rails/commands/rake/rake_command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def printing_commands
1818

1919
def perform(task, args, config)
2020
with_rake(task, *args) do |rake|
21-
if unrecognized_task = rake.top_level_tasks.find { |task| !rake.lookup(task[/[^\[]+/]) }
21+
if unrecognized_task = (rake.top_level_tasks - ["default"]).find { |task| !rake.lookup(task[/[^\[]+/]) }
2222
@rake_tasks = rake.tasks
2323
raise UnrecognizedCommandError.new(unrecognized_task)
2424
end

railties/test/command/help_integration_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class Rails::Command::HelpIntegrationTest < ActiveSupport::TestCase
4040

4141
test "prints Rake tasks on --tasks / -T option" do
4242
app_file "lib/tasks/my_task.rake", <<~RUBY
43+
Rake.application.clear
44+
4345
desc "my_task"
4446
task :my_task
4547
RUBY

0 commit comments

Comments
 (0)