-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subclass switching #136
Subclass switching #136
Changes from all commits
00a9112
6e7af17
211cd5b
93e3e89
7fffa92
09695b0
0845ce4
237ebd7
eab02f0
8c83115
61d88b6
4cf5fc7
93f67b8
c847cba
4cbafd5
34b8285
54f6ae9
db1760d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,8 +127,8 @@ 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? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this be a problem? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure :| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems super sketchy that we call not_sharded ... maybe this is a 1-off join model ... which means that it should now be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a test for this case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've tried adding a test - it's not exactly obvious where to put it though |
||
model.extend(ActiveRecordShards::Ext::ShardedModel) if model.left_reflection.klass.is_sharded? | ||
|
||
model | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,24 +3,14 @@ | |
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 | ||
ActiveSupport::Deprecation.warn("Calling not_sharded is deprecated. "\ | ||
"Please ensure to still read from the "\ | ||
"account db slave after removing the "\ | ||
"call.") | ||
end | ||
|
||
def is_sharded? # rubocop:disable Naming/PredicateName | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we seize the moment and rename There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope ;) |
||
if self == ActiveRecord::Base | ||
sharded != false && supports_sharding? | ||
elsif self == base_class | ||
if sharded.nil? | ||
ActiveRecord::Base.is_sharded? | ||
else | ||
sharded != false | ||
end | ||
else | ||
base_class.is_sharded? | ||
end | ||
false | ||
end | ||
|
||
def on_slave_by_default? | ||
|
@@ -61,9 +51,5 @@ def self.extended(base) | |
base.send(:include, InstanceMethods) | ||
base.after_initialize :initialize_shard_and_slave | ||
end | ||
|
||
private | ||
|
||
attr_accessor :sharded | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module ActiveRecordShards | ||
module Ext | ||
module ShardedModel | ||
def is_sharded? # rubocop:disable Naming/PredicateName | ||
true | ||
end | ||
end | ||
end | ||
|
||
class ShardedModel < ActiveRecord::Base | ||
self.abstract_class = true | ||
|
||
extend ActiveRecordShards::Ext::ShardedModel | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do/should we support master/slave switching without switching shards?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you're getting at?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me neither. This is fine.