Skip to content

Commit

Permalink
Merge pull request #203 from artofhuman/dont-requre-connection-on-db-…
Browse files Browse the repository at this point in the history
…prepare

Allow to use commands db:test:prepare, db:setup without created DB
  • Loading branch information
JonathanTron authored Sep 15, 2024
2 parents 1babc13 + f3c15de commit 69d268b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ Once you do that, you will see the following rake tasks among others. These are
```bash
rake db:create[env] # Create the database defined in config/database.yml for the current Rails.env
rake db:create:all # Create all the local databases defined in config/database.yml
rake db:drop[env] # Create the database defined in config/database.yml for the current Rails.env
rake db:drop[env] # Drop the database defined in config/database.yml for the current Rails.env
rake db:drop:all # Drops all the local databases defined in config/database.yml
rake db:force_close_open_connections # Forcibly close any open connections to the test database
rake db:migrate # Migrate the database to the latest version
Expand Down
8 changes: 5 additions & 3 deletions lib/sequel_rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,17 @@ def setup_controller_runtime
end

def check_skip_connect_conditions(app)
app.config.sequel[:skip_connect] ||= database_create_command?
app.config.sequel[:skip_connect] ||= skip_db_connect?
end

def database_connection_required?(app)
!app.config.sequel[:skip_connect]
end

def database_create_command?
['db:create', 'db:create:all'].any? { |c| Rake.application.top_level_tasks.include?(c) }
def skip_db_connect?
Rake.application.top_level_tasks.any? do |task|
task.match?(/^db:create|db:test:prepare|^db:drop|db:setup/)
end
end
end
end

0 comments on commit 69d268b

Please sign in to comment.