Permalink
Browse files

Merge pull request #11698 from dmathieu/sqlite_tasks_without_rails

Let the SQLite rake tasks run without rails
  • Loading branch information...
1 parent 0c366e2 commit de2a56121215d0d10c0421f01367deccfd932c00 @rafaelfranca rafaelfranca committed Sep 12, 2013
View
4 activerecord/CHANGELOG.md
@@ -1,5 +1,9 @@
## unreleased ##
+* Make possible to run SQLite rake tasks without the `Rails` constant defined.
+
+ *Damien Mathieu*
+
* Allow Relation#from to accept other relations with bind values.
*Ryan Wallace*
View
1 activerecord/lib/active_record/railtie.rb
@@ -46,6 +46,7 @@ class Railtie < Rails::Railtie # :nodoc:
ActiveRecord::Tasks::DatabaseTasks.database_configuration = Rails.application.config.database_configuration
ActiveRecord::Tasks::DatabaseTasks.migrations_paths = Rails.application.paths['db/migrate'].to_a
ActiveRecord::Tasks::DatabaseTasks.fixtures_path = File.join Rails.root, 'test', 'fixtures'
+ ActiveRecord::Tasks::DatabaseTasks.root = Rails.root
if defined?(ENGINE_PATH) && engine = Rails::Engine.find(ENGINE_PATH)
if engine.paths['db/migrate'].existent
View
3 activerecord/lib/active_record/tasks/database_tasks.rb
@@ -23,6 +23,7 @@ class DatabaseNotSupported < StandardError; end # :nodoc:
# * +fixtures_path+: a path to fixtures directory.
# * +migrations_paths+: a list of paths to directories with migrations.
# * +seed_loader+: an object which will load seeds, it needs to respond to the +load_seed+ method.
+ # * +root+: a path to the root of the application.
#
# Example usage of +DatabaseTasks+ outside Rails could look as such:
#
@@ -37,7 +38,7 @@ module DatabaseTasks
attr_writer :current_config
attr_accessor :database_configuration, :migrations_paths, :seed_loader, :db_dir,
- :fixtures_path, :env
+ :fixtures_path, :env, :root
LOCAL_HOSTS = ['127.0.0.1', 'localhost']
View
2 activerecord/lib/active_record/tasks/sqlite_database_tasks.rb
@@ -3,7 +3,7 @@ module Tasks # :nodoc:
class SQLiteDatabaseTasks # :nodoc:
delegate :connection, :establish_connection, to: ActiveRecord::Base
- def initialize(configuration, root = Rails.root)
+ def initialize(configuration, root = ActiveRecord::Tasks::DatabaseTasks.root)
@configuration, @root = configuration, root
end

0 comments on commit de2a561

Please sign in to comment.