Skip to content

Commit

Permalink
Remove ActiveRecordShards::Model.not_sharded
Browse files Browse the repository at this point in the history
  • Loading branch information
bquorning committed Oct 11, 2017
1 parent f66c783 commit c00a1b6
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ basically connections inherit configuration from the parent configuration file.
## Usage

Normally you have some models that live on a shared database, and you might need to query this data in order to know what shard to switch to.
All the models that live on the shared database must be marked as not\_sharded:
All the models that live on the sharded database must be marked with `self.sharded = true`:

class Account < ActiveRecord::Base
not_sharded

has_many :projects
end

class Project < ActiveRecord::Base
self.sharded = true

belongs_to :account
end

Expand Down
2 changes: 0 additions & 2 deletions lib/active_record_shards/default_slave_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ def model.on_slave_by_default?
left_reflection.klass.on_slave_by_default?
end

# also transfer the sharded-ness of the left table to the join model
model.not_sharded unless model.left_reflection.klass.is_sharded?
model
end
end
Expand Down
7 changes: 0 additions & 7 deletions lib/active_record_shards/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

module ActiveRecordShards
module Model
def not_sharded
if self != ActiveRecord::Base && self != base_class
raise "You should only call not_sharded on direct descendants of ActiveRecord::Base"
end
self.sharded = false
end

def is_sharded? # rubocop:disable Style/PredicateName
if self == ActiveRecord::Base
# sharded != false && supports_sharding?
Expand Down
2 changes: 0 additions & 2 deletions lib/active_record_shards/patches-5-0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@


ActiveRecord::Associations::Builder::HasAndBelongsToMany.include(ActiveRecordShards::DefaultSlavePatches::Rails41HasAndBelongsToManyBuilderExtension)

ActiveRecord::InternalMetadata.not_sharded
1 change: 0 additions & 1 deletion test/connection_switching_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ def clear_connection_pool
describe "for unsharded models" do
it "use the unsharded slave connection" do
class UnshardedModel < ActiveRecord::Base
# not_sharded
end

UnshardedModel.on_slave { UnshardedModel.connection.execute("create table unsharded_models (id int)") }
Expand Down

0 comments on commit c00a1b6

Please sign in to comment.