Module: XBar::Migration
- Defined in:
- lib/xbar/migration.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#get_current_shard ⇒ Object
Used by migration when printing out results.
- #migrate_with_xbar(direction) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/xbar/migration.rb', line 3 def self.extended(base) class << base def () ("#{} - #{get_current_shard}") end alias_method_chain :migrate, :xbar alias_method_chain :announce, :xbar attr_accessor :current_shard end end |
.included(base) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/xbar/migration.rb', line 14 def self.included(base) base.class_eval do def () ("#{} - #{get_current_shard}") end alias_method_chain :migrate, :xbar alias_method_chain :announce, :xbar attr_accessor :current_shard end base.extend(ClassMethods) end |
Instance Method Details
#get_current_shard ⇒ Object
Used by migration when printing out results.
64 65 66 67 68 |
# File 'lib/xbar/migration.rb', line 64 def get_current_shard if ActiveRecord::Base.connection.respond_to?(:current_shard) "Shard: #{ActiveRecord::Base.connection.current_shard}" end end |
#migrate_with_xbar(direction) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/xbar/migration.rb', line 45 def (direction) conn = ActiveRecord::Base.connection raise "XBar::Migration#mismatched connections" unless conn == self.connection if conn.kind_of?(XBar::Proxy) u2 = self.class.instance_variable_get(:@current_shard) conn.current_shard = u2 if u2 conn.send_queries_to_multiple_shards(conn.current_shard) do (direction) end else (direction) end ensure if conn.kind_of?(XBar::Proxy) conn.clean_proxy end end |