From 18a021bcabbbd4a97e2ebc4ec3a721c81c280df5 Mon Sep 17 00:00:00 2001 From: Rolf Timmermans Date: Wed, 29 Nov 2017 16:58:21 +0100 Subject: [PATCH 1/4] Do not connect automatically from rakefile, but explicitly when needed. --- lib/sequel_rails/railtie.rb | 2 +- lib/sequel_rails/railties/database.rake | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/sequel_rails/railtie.rb b/lib/sequel_rails/railtie.rb index 6c8c408..f39bd46 100755 --- a/lib/sequel_rails/railtie.rb +++ b/lib/sequel_rails/railtie.rb @@ -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 defined?(::Rake) end initializer 'sequel.spring' do |_app| diff --git a/lib/sequel_rails/railties/database.rake b/lib/sequel_rails/railties/database.rake index 04a8dc1..064b8ee 100644 --- a/lib/sequel_rails/railties/database.rake +++ b/lib/sequel_rails/railties/database.rake @@ -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') @@ -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.' From fd4668fcd0cb1679c41dc63ecc3abe67b5e17a8f Mon Sep 17 00:00:00 2001 From: Rolf Timmermans Date: Wed, 29 Nov 2017 17:05:44 +0100 Subject: [PATCH 2/4] Connect before running tests. --- spec/spec_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 33a3228..7d09e47 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 From cfbf4a9c14f27158b26a31afd3d722cd7ecddda9 Mon Sep 17 00:00:00 2001 From: Rolf Timmermans Date: Wed, 6 Dec 2017 16:27:43 +0100 Subject: [PATCH 3/4] Alternative check to see if rake is running. --- lib/sequel_rails/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sequel_rails/railtie.rb b/lib/sequel_rails/railtie.rb index f39bd46..8ba52b1 100755 --- a/lib/sequel_rails/railtie.rb +++ b/lib/sequel_rails/railtie.rb @@ -68,7 +68,7 @@ class Railtie < Rails::Railtie end initializer 'sequel.connect' do |app| - ::SequelRails.setup ::Rails.env unless app.config.sequel[:skip_connect] or defined?(::Rake) + ::SequelRails.setup ::Rails.env unless app.config.sequel[:skip_connect] or $rails_rake_task end initializer 'sequel.spring' do |_app| From a656eafbe702e2b466a694306c2c7d686cb699ca Mon Sep 17 00:00:00 2001 From: Rolf Timmermans Date: Wed, 6 Dec 2017 17:50:36 +0100 Subject: [PATCH 4/4] Alternative check to see if rake is running. --- lib/sequel_rails/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sequel_rails/railtie.rb b/lib/sequel_rails/railtie.rb index 8ba52b1..20f4c42 100755 --- a/lib/sequel_rails/railtie.rb +++ b/lib/sequel_rails/railtie.rb @@ -68,7 +68,7 @@ class Railtie < Rails::Railtie end initializer 'sequel.connect' do |app| - ::SequelRails.setup ::Rails.env unless app.config.sequel[:skip_connect] or $rails_rake_task + ::SequelRails.setup ::Rails.env unless app.config.sequel[:skip_connect] or $0 =~ /rake/ end initializer 'sequel.spring' do |_app|