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

Fix db:create rake tasks #145

Merged
merged 4 commits into from
Feb 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/sequel_rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Railtie < Rails::Railtie
end

initializer 'sequel.connect' do |app|
::SequelRails.setup ::Rails.env unless app.config.sequel[:skip_connect]
::SequelRails.setup ::Rails.env unless app.config.sequel[:skip_connect] or $0 =~ /rake/

Choose a reason for hiding this comment

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

It might be good to turn this into a method at this point. The conditional is becoming obtuse.

How about extracting a should_connect? method with these two conditions.

Railtie also has a rake hook where you could simply set app.config.sequel[:skip_connect] to true perhaps. I pored over ActiveRecord's railtie to figure out how they're avoiding this issue and couldn't find anything obvious to copy and reuse here.

end

initializer 'sequel.spring' do |_app|
Expand Down
2 changes: 2 additions & 0 deletions lib/sequel_rails/railties/database.rake
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace sequel_rails_namespace do
namespace :structure do
desc 'Dump the database structure to db/structure.sql'
task :dump, [:env] => :environment do |_t, args|
db_for_current_env
args.with_defaults(:env => Rails.env)

filename = ENV['DB_STRUCTURE'] || File.join(Rails.root, 'db', 'structure.sql')
Expand Down Expand Up @@ -126,6 +127,7 @@ namespace sequel_rails_namespace do
namespace :migrate do
task :load => :environment do
require 'sequel_rails/migrations'
db_for_current_env
end

desc 'Rollbacks the database one migration and re migrate up. If you want to rollback more than one step, define STEP=x. Target specific version with VERSION=x.'
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
begin
require 'sequel_rails/storage'
require 'sequel/extensions/migration'
::SequelRails.setup(Rails.env)
load "#{Rails.root}/db/schema.rb.init"
Sequel::Migration.descendants.first.apply Sequel::Model.db, :up
rescue Sequel::DatabaseConnectionError => e
Expand Down