ar-octopus 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +9 -9
  2. data/.rspec +1 -1
  3. data/.rubocop.yml +46 -0
  4. data/.rubocop_todo.yml +52 -0
  5. data/.ruby-version +1 -1
  6. data/.travis.yml +3 -9
  7. data/Appraisals +4 -0
  8. data/Rakefile +17 -16
  9. data/ar-octopus.gemspec +22 -16
  10. data/gemfiles/rails41.gemfile +7 -0
  11. data/init.rb +1 -1
  12. data/lib/ar-octopus.rb +1 -1
  13. data/lib/octopus.rb +38 -37
  14. data/lib/octopus/abstract_adapter.rb +0 -2
  15. data/lib/octopus/association.rb +8 -6
  16. data/lib/octopus/association_shard_tracking.rb +80 -81
  17. data/lib/octopus/collection_association.rb +7 -5
  18. data/lib/octopus/collection_proxy.rb +11 -9
  19. data/lib/octopus/has_and_belongs_to_many_association.rb +5 -3
  20. data/lib/octopus/load_balancing.rb +3 -2
  21. data/lib/octopus/load_balancing/round_robin.rb +12 -8
  22. data/lib/octopus/migration.rb +117 -108
  23. data/lib/octopus/model.rb +130 -134
  24. data/lib/octopus/persistence.rb +1 -1
  25. data/lib/octopus/proxy.rb +345 -339
  26. data/lib/octopus/railtie.rb +2 -2
  27. data/lib/octopus/relation_proxy.rb +6 -1
  28. data/lib/octopus/scope_proxy.rb +38 -36
  29. data/lib/octopus/shard_tracking.rb +36 -35
  30. data/lib/octopus/shard_tracking/attribute.rb +12 -14
  31. data/lib/octopus/shard_tracking/dynamic.rb +7 -3
  32. data/lib/octopus/singular_association.rb +5 -3
  33. data/lib/octopus/slave_group.rb +10 -8
  34. data/lib/octopus/version.rb +1 -1
  35. data/rails/init.rb +1 -1
  36. data/sample_app/autotest/discover.rb +2 -2
  37. data/sample_app/config/application.rb +1 -1
  38. data/sample_app/config/boot.rb +1 -1
  39. data/sample_app/config/environments/test.rb +1 -1
  40. data/sample_app/config/initializers/session_store.rb +1 -1
  41. data/sample_app/config/initializers/wrap_parameters.rb +1 -1
  42. data/sample_app/config/routes.rb +1 -1
  43. data/sample_app/db/migrate/20100720210335_create_sample_users.rb +2 -2
  44. data/sample_app/db/schema.rb +10 -10
  45. data/sample_app/db/seeds.rb +3 -3
  46. data/sample_app/features/step_definitions/seeds_steps.rb +4 -4
  47. data/sample_app/features/step_definitions/web_steps.rb +3 -4
  48. data/sample_app/features/support/env.rb +3 -4
  49. data/sample_app/features/support/paths.rb +4 -4
  50. data/sample_app/spec/spec_helper.rb +3 -3
  51. data/spec/migrations/10_create_users_using_replication.rb +3 -3
  52. data/spec/migrations/11_add_field_in_all_slaves.rb +3 -3
  53. data/spec/migrations/12_create_users_using_block.rb +7 -7
  54. data/spec/migrations/13_create_users_using_block_and_using.rb +4 -4
  55. data/spec/migrations/14_create_users_on_shards_of_a_group_with_versions.rb +2 -2
  56. data/spec/migrations/15_create_user_on_shards_of_default_group_with_versions.rb +2 -2
  57. data/spec/migrations/1_create_users_on_master.rb +3 -3
  58. data/spec/migrations/2_create_users_on_canada.rb +3 -3
  59. data/spec/migrations/3_create_users_on_both_shards.rb +3 -3
  60. data/spec/migrations/4_create_users_on_shards_of_a_group.rb +3 -3
  61. data/spec/migrations/5_create_users_on_multiples_groups.rb +2 -2
  62. data/spec/migrations/6_raise_exception_with_invalid_shard_name.rb +3 -3
  63. data/spec/migrations/7_raise_exception_with_invalid_multiple_shard_names.rb +3 -3
  64. data/spec/migrations/8_raise_exception_with_invalid_group_name.rb +3 -3
  65. data/spec/migrations/9_raise_exception_with_multiple_invalid_group_names.rb +4 -4
  66. data/spec/octopus/association_shard_tracking_spec.rb +413 -417
  67. data/spec/octopus/collection_proxy_spec.rb +6 -5
  68. data/spec/octopus/log_subscriber_spec.rb +4 -4
  69. data/spec/octopus/migration_spec.rb +48 -48
  70. data/spec/octopus/model_spec.rb +267 -292
  71. data/spec/octopus/octopus_spec.rb +40 -41
  72. data/spec/octopus/proxy_spec.rb +124 -124
  73. data/spec/octopus/relation_proxy_spec.rb +32 -32
  74. data/spec/octopus/replicated_slave_grouped_spec.rb +23 -23
  75. data/spec/octopus/replication_spec.rb +61 -66
  76. data/spec/octopus/scope_proxy_spec.rb +56 -10
  77. data/spec/octopus/sharded_replicated_slave_grouped_spec.rb +29 -29
  78. data/spec/octopus/sharded_spec.rb +10 -10
  79. data/spec/spec_helper.rb +6 -6
  80. data/spec/support/active_record/connection_adapters/modify_config_adapter.rb +1 -3
  81. data/spec/support/database_connection.rb +2 -2
  82. data/spec/support/database_models.rb +16 -17
  83. data/spec/support/octopus_helper.rb +19 -21
  84. data/spec/support/query_count.rb +1 -3
  85. data/spec/support/shared_contexts.rb +3 -3
  86. data/spec/tasks/octopus.rake_spec.rb +10 -10
  87. metadata +43 -26
@@ -2,7 +2,6 @@
2
2
  module Octopus
3
3
  module AbstractAdapter
4
4
  module OctopusShard
5
-
6
5
  parent = Octopus.rails3? ? ActiveSupport::BasicObject : ActiveSupport::ProxyObject
7
6
 
8
7
  class InstrumenterDecorator < parent
@@ -33,7 +32,6 @@ module Octopus
33
32
  initialize_without_octopus_shard(*args)
34
33
  @instrumenter = InstrumenterDecorator.new(self, @instrumenter)
35
34
  end
36
-
37
35
  end
38
36
  end
39
37
  end
@@ -1,10 +1,12 @@
1
- module Octopus::Association
2
- def self.included(base)
3
- base.send(:include, Octopus::ShardTracking::Dynamic)
4
- end
1
+ module Octopus
2
+ module Association
3
+ def self.included(base)
4
+ base.send(:include, Octopus::ShardTracking::Dynamic)
5
+ end
5
6
 
6
- def current_shard
7
- owner.current_shard
7
+ def current_shard
8
+ owner.current_shard
9
+ end
8
10
  end
9
11
  end
10
12
 
@@ -1,104 +1,103 @@
1
- module Octopus::AssociationShardTracking
2
- def self.extended(base)
3
- base.send(:include, InstanceMethods)
4
- end
5
-
6
- module QueryOnCurrentShard
1
+ module Octopus
2
+ module AssociationShardTracking
3
+ def self.extended(base)
4
+ base.send(:include, InstanceMethods)
5
+ end
7
6
 
8
- METHODS= %w[
9
- all
10
- average
11
- count
12
- empty?
13
- exists?
14
- find
15
- find_by_sql
16
- first
17
- last
18
- maximum
19
- minimum
20
- pluck
21
- scoping
22
- size
23
- sum
24
- to_a
25
- ]
7
+ module QueryOnCurrentShard
8
+ METHODS = %w(
9
+ all
10
+ average
11
+ count
12
+ empty?
13
+ exists?
14
+ find
15
+ find_by_sql
16
+ first
17
+ last
18
+ maximum
19
+ minimum
20
+ pluck
21
+ scoping
22
+ size
23
+ sum
24
+ to_a
25
+ )
26
26
 
27
- METHODS.each do |m|
28
- define_method m.to_sym do |*args,&block|
29
- if self.respond_to?(:proxy_association) and self.proxy_association
30
- self.proxy_association.owner.run_on_shard { super(*args, &block) }
31
- else
32
- super(*args, &block)
27
+ METHODS.each do |m|
28
+ define_method m.to_sym do |*args, &block|
29
+ if self.respond_to?(:proxy_association) && proxy_association
30
+ proxy_association.owner.run_on_shard { super(*args, &block) }
31
+ else
32
+ super(*args, &block)
33
+ end
33
34
  end
34
35
  end
35
36
  end
36
37
 
37
- end
38
+ module InstanceMethods
39
+ def connection_on_association=(record)
40
+ return unless ::Octopus.enabled?
41
+ return if !self.class.connection.respond_to?(:current_shard) || !self.respond_to?(:current_shard)
42
+ if !record.current_shard.nil? && !current_shard.nil? && record.current_shard != current_shard
43
+ fail 'Association Error: Records are from different shards'
44
+ end
38
45
 
39
- module InstanceMethods
40
- def set_connection_on_association(record)
41
- return unless ::Octopus.enabled?
42
- return if !self.class.connection.respond_to?(:current_shard) || !self.respond_to?(:current_shard)
43
- if !record.current_shard.nil? && !self.current_shard.nil? && record.current_shard != self.current_shard
44
- raise "Association Error: Records are from different shards"
46
+ record.current_shard = self.class.connection.current_shard = current_shard if should_set_current_shard?
45
47
  end
46
-
47
- record.current_shard = self.class.connection.current_shard = self.current_shard if should_set_current_shard?
48
48
  end
49
- end
50
49
 
51
- if Octopus.rails4?
52
- def has_many(association_id, scope=nil, options={}, &extension)
53
- if options == {} && scope.is_a?(Hash)
54
- default_octopus_opts(scope)
55
- else
50
+ if Octopus.rails4?
51
+ def has_many(association_id, scope = nil, options = {}, &extension)
52
+ if options == {} && scope.is_a?(Hash)
53
+ default_octopus_opts(scope)
54
+ else
55
+ default_octopus_opts(options)
56
+ end
57
+ super
58
+ end
59
+ else
60
+ def has_many(association_id, options = {}, &extension)
56
61
  default_octopus_opts(options)
62
+ super
57
63
  end
58
- super
59
- end
60
- else
61
- def has_many(association_id, options={}, &extension)
62
- default_octopus_opts(options)
63
- super
64
64
  end
65
- end
66
-
67
65
 
68
- if Octopus.rails4?
69
- def has_and_belongs_to_many(association_id, scope=nil, options={}, &extension)
70
- if options == {} && scope.is_a?(Hash)
71
- default_octopus_opts(scope)
72
- else
66
+ if Octopus.rails4?
67
+ def has_and_belongs_to_many(association_id, scope = nil, options = {}, &extension)
68
+ if options == {} && scope.is_a?(Hash)
69
+ default_octopus_opts(scope)
70
+ else
71
+ default_octopus_opts(options)
72
+ end
73
+ super
74
+ end
75
+ else
76
+ def has_and_belongs_to_many(association_id, options = {}, &extension)
73
77
  default_octopus_opts(options)
78
+ super
74
79
  end
75
- super
76
- end
77
- else
78
- def has_and_belongs_to_many(association_id, options={}, &extension)
79
- default_octopus_opts(options)
80
- super
81
80
  end
82
- end
83
81
 
84
- def default_octopus_opts(options)
85
- if options[:before_add].is_a?(Array)
86
- options[:before_add] << :set_connection_on_association
87
- elsif options[:before_add].is_a?(Symbol)
88
- options[:before_add] = [:set_connection_on_association, options[:before_add]]
89
- else
90
- options[:before_add] = :set_connection_on_association
91
- end
82
+ def default_octopus_opts(options)
83
+ if options[:before_add].is_a?(Array)
84
+ options[:before_add] << :connection_on_association=
85
+ elsif options[:before_add].is_a?(Symbol)
86
+ options[:before_add] = [:connection_on_association=, options[:before_add]]
87
+ else
88
+ options[:before_add] = :connection_on_association=
89
+ end
92
90
 
93
- if options[:before_remove].is_a?(Array)
94
- options[:before_remove] << :set_connection_on_association
95
- elsif options[:before_remove].is_a?(Symbol)
96
- options[:before_remove] = [:set_connection_on_association, options[:before_remove]]
97
- else
98
- options[:before_remove] = :set_connection_on_association
99
- end
91
+ if options[:before_remove].is_a?(Array)
92
+ options[:before_remove] << :connection_on_association=
93
+ elsif options[:before_remove].is_a?(Symbol)
94
+ options[:before_remove] = [:connection_on_association=, options[:before_remove]]
95
+ else
96
+ options[:before_remove] = :connection_on_association=
97
+ end
100
98
 
101
- options[:extend] = [ Octopus::AssociationShardTracking::QueryOnCurrentShard, options[:extend] ].flatten.compact
99
+ options[:extend] = [Octopus::AssociationShardTracking::QueryOnCurrentShard, options[:extend]].flatten.compact
100
+ end
102
101
  end
103
102
  end
104
103
 
@@ -1,8 +1,10 @@
1
- module Octopus::CollectionAssociation
2
- def self.included(base)
3
- base.sharded_methods :reader, :writer, :ids_reader, :ids_writer, :create, :create!,
4
- :build, :any?, :count, :empty?, :first, :include?, :last, :length,
5
- :load_target, :many?, :reload, :size, :select, :uniq
1
+ module Octopus
2
+ module CollectionAssociation
3
+ def self.included(base)
4
+ base.sharded_methods :reader, :writer, :ids_reader, :ids_writer, :create, :create!,
5
+ :build, :any?, :count, :empty?, :first, :include?, :last, :length,
6
+ :load_target, :many?, :reload, :size, :select, :uniq
7
+ end
6
8
  end
7
9
  end
8
10
 
@@ -1,13 +1,15 @@
1
- module Octopus::CollectionProxy
2
- def self.included(base)
3
- base.send(:include, Octopus::ShardTracking::Dynamic)
4
- base.sharded_methods :any?, :build, :count, :create, :create!, :concat, :delete, :delete_all,
5
- :destroy, :destroy_all, :empty?, :find, :first, :include?, :last, :length,
6
- :many?, :pluck, :replace, :select, :size, :sum, :to_a, :uniq
7
- end
1
+ module Octopus
2
+ module CollectionProxy
3
+ def self.included(base)
4
+ base.send(:include, Octopus::ShardTracking::Dynamic)
5
+ base.sharded_methods :any?, :build, :count, :create, :create!, :concat, :delete, :delete_all,
6
+ :destroy, :destroy_all, :empty?, :find, :first, :include?, :last, :length,
7
+ :many?, :pluck, :replace, :select, :size, :sum, :to_a, :uniq
8
+ end
8
9
 
9
- def current_shard
10
- @association.owner.current_shard
10
+ def current_shard
11
+ @association.owner.current_shard
12
+ end
11
13
  end
12
14
  end
13
15
 
@@ -1,6 +1,8 @@
1
- module Octopus::HasAndBelongsToManyAssociation
2
- def self.included(base)
3
- base.sharded_methods :insert_record
1
+ module Octopus
2
+ module HasAndBelongsToManyAssociation
3
+ def self.included(base)
4
+ base.sharded_methods :insert_record
5
+ end
4
6
  end
5
7
  end
6
8
 
@@ -1,3 +1,4 @@
1
- module Octopus::LoadBalancing
2
-
1
+ module Octopus
2
+ module LoadBalancing
3
+ end
3
4
  end
@@ -2,14 +2,18 @@ require 'octopus/load_balancing'
2
2
 
3
3
  # The round-robin load balancing of slaves belonging to the same shard.
4
4
  # It is a pool that contains slaves which queries are distributed to.
5
- class Octopus::LoadBalancing::RoundRobin
6
- def initialize(slaves_list)
7
- @slaves_list = slaves_list
8
- @slave_index = 0
9
- end
5
+ module Octopus
6
+ module LoadBalancing
7
+ class RoundRobin
8
+ def initialize(slaves_list)
9
+ @slaves_list = slaves_list
10
+ @slave_index = 0
11
+ end
10
12
 
11
- # Returns the next available slave in the pool
12
- def next
13
- @slaves_list[@slave_index = (@slave_index + 1) % @slaves_list.length]
13
+ # Returns the next available slave in the pool
14
+ def next
15
+ @slaves_list[@slave_index = (@slave_index + 1) % @slaves_list.length]
16
+ end
17
+ end
14
18
  end
15
19
  end
@@ -1,155 +1,164 @@
1
- require "set"
2
- require "active_support/core_ext/module/aliasing"
3
- require "active_support/core_ext/array/wrap"
4
-
5
- module Octopus::Migration
6
- module InstanceOrClassMethods
7
- def announce_with_octopus(message)
8
- announce_without_octopus("#{message} - #{get_current_shard}")
9
- end
1
+ require 'set'
2
+ require 'active_support/core_ext/module/aliasing'
3
+ require 'active_support/core_ext/array/wrap'
4
+
5
+ module Octopus
6
+ module Migration
7
+ module InstanceOrClassMethods
8
+ def announce_with_octopus(message)
9
+ announce_without_octopus("#{message} - #{current_shard}")
10
+ end
10
11
 
11
- def get_current_shard
12
- "Shard: #{connection.current_shard}" if connection.respond_to?(:current_shard)
12
+ def current_shard
13
+ "Shard: #{connection.current_shard}" if connection.respond_to?(:current_shard)
14
+ end
13
15
  end
14
- end
15
16
 
16
- include InstanceOrClassMethods
17
+ include InstanceOrClassMethods
17
18
 
18
- def self.included(base)
19
- base.extend(ClassMethods)
19
+ def self.included(base)
20
+ base.extend(ClassMethods)
20
21
 
21
- base.alias_method_chain :announce, :octopus
22
- base.class_attribute :current_shard, :current_group, :current_group_specified, :instance_reader => false, :instance_writer => false
23
- end
22
+ base.alias_method_chain :announce, :octopus
23
+ base.class_attribute :current_shard, :current_group, :current_group_specified, :instance_reader => false, :instance_writer => false
24
+ end
24
25
 
25
- module ClassMethods
26
- def using(*args)
27
- return self unless connection.is_a?(Octopus::Proxy)
26
+ module ClassMethods
27
+ def using(*args)
28
+ return self unless connection.is_a?(Octopus::Proxy)
28
29
 
29
- self.current_shard = args
30
- self
31
- end
30
+ self.current_shard = args
31
+ self
32
+ end
32
33
 
33
- def using_group(*groups)
34
- return self unless connection.is_a?(Octopus::Proxy)
34
+ def using_group(*groups)
35
+ return self unless connection.is_a?(Octopus::Proxy)
35
36
 
36
- self.current_group = groups
37
- self.current_group_specified = true
38
- self
39
- end
37
+ self.current_group = groups
38
+ self.current_group_specified = true
39
+ self
40
+ end
40
41
 
41
- def shards
42
- shards = Set.new
42
+ def shards
43
+ shards = Set.new
43
44
 
44
- if groups = (current_group_specified ? current_group : Octopus.config[:default_migration_group])
45
- Array.wrap(groups).each do |group|
46
- group_shards = connection.shards_for_group(group)
47
- shards.merge(group_shards) if group_shards
45
+ if (groups = (current_group_specified ? current_group : Octopus.config[:default_migration_group]))
46
+ Array.wrap(groups).each do |group|
47
+ group_shards = connection.shards_for_group(group)
48
+ shards.merge(group_shards) if group_shards
49
+ end
50
+ elsif (shard = current_shard)
51
+ shards.merge(Array.wrap(shard))
48
52
  end
49
- elsif shard = current_shard
50
- shards.merge(Array.wrap(shard))
51
- end
52
53
 
53
- shards.to_a.presence || [:master]
54
+ shards.to_a.presence || [:master]
55
+ end
54
56
  end
55
57
  end
56
58
  end
57
59
 
58
- module Octopus::Migrator
59
- def self.included(base)
60
- base.extend(ClassMethods)
61
-
62
- base.class_eval do
63
- class << self
64
- alias_method_chain :migrate, :octopus
65
- alias_method_chain :up, :octopus
66
- alias_method_chain :down, :octopus
67
- alias_method_chain :run, :octopus
60
+ module Octopus
61
+ module Migrator
62
+ def self.included(base)
63
+ base.extend(ClassMethods)
64
+
65
+ base.class_eval do
66
+ class << self
67
+ alias_method_chain :migrate, :octopus
68
+ alias_method_chain :up, :octopus
69
+ alias_method_chain :down, :octopus
70
+ alias_method_chain :run, :octopus
71
+ end
68
72
  end
69
- end
70
73
 
71
- base.alias_method_chain :run, :octopus
72
- base.alias_method_chain :migrate, :octopus
73
- base.alias_method_chain :migrations, :octopus
74
- end
74
+ base.alias_method_chain :run, :octopus
75
+ base.alias_method_chain :migrate, :octopus
76
+ base.alias_method_chain :migrations, :octopus
77
+ end
75
78
 
76
- def run_with_octopus(&block)
77
- run_without_octopus(&block)
78
- rescue ActiveRecord::UnknownMigrationVersionError => e
79
- raise unless migrations(true).find {|m| m.version == e.version}
80
- end
79
+ def run_with_octopus(&block)
80
+ run_without_octopus(&block)
81
+ rescue ActiveRecord::UnknownMigrationVersionError => e
82
+ raise unless migrations(true).detect { |m| m.version == e.version }
83
+ end
81
84
 
82
- def migrate_with_octopus(&block)
83
- migrate_without_octopus(&block)
84
- rescue ActiveRecord::UnknownMigrationVersionError => e
85
- raise unless migrations(true).find {|m| m.version == e.version}
86
- end
85
+ def migrate_with_octopus(&block)
86
+ migrate_without_octopus(&block)
87
+ rescue ActiveRecord::UnknownMigrationVersionError => e
88
+ raise unless migrations(true).detect { |m| m.version == e.version }
89
+ end
87
90
 
88
- def migrations_with_octopus(shard_agnostic = false)
89
- connection = ActiveRecord::Base.connection
90
- migrations = migrations_without_octopus
91
- return migrations if !connection.is_a?(Octopus::Proxy) || shard_agnostic
91
+ def migrations_with_octopus(shard_agnostic = false)
92
+ connection = ActiveRecord::Base.connection
93
+ migrations = migrations_without_octopus
94
+ return migrations if !connection.is_a?(Octopus::Proxy) || shard_agnostic
92
95
 
93
- migrations.select {|m| m.shards.include?(connection.current_shard.to_sym)}
94
- end
96
+ migrations.select { |m| m.shards.include?(connection.current_shard.to_sym) }
97
+ end
95
98
 
96
- module ClassMethods
97
- def migrate_with_octopus(migrations_paths, target_version = nil, &block)
98
- return migrate_without_octopus(migrations_paths, target_version, &block) unless connection.is_a?(Octopus::Proxy)
99
+ module ClassMethods
100
+ def migrate_with_octopus(migrations_paths, target_version = nil, &block)
101
+ return migrate_without_octopus(migrations_paths, target_version, &block) unless connection.is_a?(Octopus::Proxy)
99
102
 
100
- connection.send_queries_to_multiple_shards(connection.shard_names) do
101
- migrate_without_octopus(migrations_paths, target_version, &block)
103
+ connection.send_queries_to_multiple_shards(connection.shard_names) do
104
+ migrate_without_octopus(migrations_paths, target_version, &block)
105
+ end
102
106
  end
103
- end
104
107
 
105
- def up_with_octopus(migrations_paths, target_version = nil, &block)
106
- return up_without_octopus(migrations_paths, target_version, &block) unless connection.is_a?(Octopus::Proxy)
107
- return up_without_octopus(migrations_paths, target_version, &block) unless connection.current_shard == :master
108
+ def up_with_octopus(migrations_paths, target_version = nil, &block)
109
+ return up_without_octopus(migrations_paths, target_version, &block) unless connection.is_a?(Octopus::Proxy)
110
+ return up_without_octopus(migrations_paths, target_version, &block) unless connection.current_shard == :master
108
111
 
109
- connection.send_queries_to_multiple_shards(connection.shard_names) do
110
- up_without_octopus(migrations_paths, target_version, &block)
112
+ connection.send_queries_to_multiple_shards(connection.shard_names) do
113
+ up_without_octopus(migrations_paths, target_version, &block)
114
+ end
111
115
  end
112
- end
113
116
 
114
- def down_with_octopus(migrations_paths, target_version = nil, &block)
115
- return down_without_octopus(migrations_paths, target_version, &block) unless connection.is_a?(Octopus::Proxy)
116
- return down_without_octopus(migrations_paths, target_version, &block) unless connection.current_shard == :master
117
+ def down_with_octopus(migrations_paths, target_version = nil, &block)
118
+ return down_without_octopus(migrations_paths, target_version, &block) unless connection.is_a?(Octopus::Proxy)
119
+ return down_without_octopus(migrations_paths, target_version, &block) unless connection.current_shard == :master
117
120
 
118
- connection.send_queries_to_multiple_shards(connection.shard_names) do
119
- down_without_octopus(migrations_paths, target_version, &block)
121
+ connection.send_queries_to_multiple_shards(connection.shard_names) do
122
+ down_without_octopus(migrations_paths, target_version, &block)
123
+ end
120
124
  end
121
- end
122
125
 
123
- def run_with_octopus(direction, migrations_paths, target_version)
124
- return run_without_octopus(direction, migrations_paths, target_version) unless connection.is_a?(Octopus::Proxy)
126
+ def run_with_octopus(direction, migrations_paths, target_version)
127
+ return run_without_octopus(direction, migrations_paths, target_version) unless connection.is_a?(Octopus::Proxy)
125
128
 
126
- connection.send_queries_to_multiple_shards(connection.shard_names) do
127
- run_without_octopus(direction, migrations_paths, target_version)
129
+ connection.send_queries_to_multiple_shards(connection.shard_names) do
130
+ run_without_octopus(direction, migrations_paths, target_version)
131
+ end
128
132
  end
129
- end
130
133
 
131
- private
132
- def connection
133
- ActiveRecord::Base.connection
134
+ private
135
+
136
+ def connection
137
+ ActiveRecord::Base.connection
138
+ end
134
139
  end
135
140
  end
136
141
  end
137
142
 
138
- module Octopus::MigrationProxy
139
- def shards
140
- migration.class.shards
143
+ module Octopus
144
+ module MigrationProxy
145
+ def shards
146
+ migration.class.shards
147
+ end
141
148
  end
142
149
  end
143
150
 
144
- module Octopus::UnknownMigrationVersionError
145
- def self.included(base)
146
- base.alias_method_chain :initialize, :octopus
147
- base.send(:attr_accessor, :version)
148
- end
151
+ module Octopus
152
+ module UnknownMigrationVersionError
153
+ def self.included(base)
154
+ base.alias_method_chain :initialize, :octopus
155
+ base.send(:attr_accessor, :version)
156
+ end
149
157
 
150
- def initialize_with_octopus(version)
151
- @version = version
152
- initialize_without_octopus(version)
158
+ def initialize_with_octopus(version)
159
+ @version = version
160
+ initialize_without_octopus(version)
161
+ end
153
162
  end
154
163
  end
155
164