lib/lhm.rb in lhm-1.1.0 vs lib/lhm.rb in lhm-1.2.0
- old
+ new
@@ -1,11 +1,11 @@
-# Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
+# Copyright (c) 2011 - 2013, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
# Schmidt
-require 'active_record'
require 'lhm/table'
require 'lhm/invoker'
+require 'lhm/connection'
require 'lhm/version'
# Large hadron migrator - online schema change tool
#
# @example
@@ -32,14 +32,27 @@
# to set this option (see SqlHelper#supports_atomic_switch?)
# @yield [Migrator] Yielded Migrator object records the changes
# @return [Boolean] Returns true if the migration finishes
# @raise [Error] Raises Lhm::Error in case of a error and aborts the migration
def self.change_table(table_name, options = {}, &block)
- connection = ActiveRecord::Base.connection
+ connection = Connection.new(adapter)
+
origin = Table.parse(table_name, connection)
invoker = Invoker.new(origin, connection)
block.call(invoker.migrator)
invoker.run(options)
true
+ end
+
+ def self.setup(adapter)
+ @@adapter = adapter
+ end
+
+ def self.adapter
+ @@adapter ||=
+ begin
+ raise 'Please call Lhm.setup' unless defined?(ActiveRecord)
+ ActiveRecord::Base.connection
+ end
end
end