activerecord-turntable 3.0.0.alpha3 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +3 -0
- data/.rubocop.yml +18 -0
- data/.rubocop_todo.yml +153 -0
- data/.travis.yml +20 -4
- data/CHANGELOG.md +32 -0
- data/Guardfile +2 -2
- data/README.md +68 -14
- data/Rakefile +42 -0
- data/activerecord-turntable.gemspec +13 -3
- data/gemfiles/rails_edge.gemfile +8 -0
- data/lib/active_record/turntable/active_record_ext/abstract_adapter.rb +3 -1
- data/lib/active_record/turntable/active_record_ext/activerecord_import_ext.rb +5 -7
- data/lib/active_record/turntable/active_record_ext/acts_as_archive_extension.rb +2 -2
- data/lib/active_record/turntable/active_record_ext/association.rb +3 -3
- data/lib/active_record/turntable/active_record_ext/clever_load.rb +2 -2
- data/lib/active_record/turntable/active_record_ext/database_tasks.rb +10 -8
- data/lib/active_record/turntable/active_record_ext/fixtures.rb +15 -13
- data/lib/active_record/turntable/active_record_ext/log_subscriber.rb +6 -0
- data/lib/active_record/turntable/active_record_ext/persistence.rb +25 -23
- data/lib/active_record/turntable/active_record_ext/schema_dumper.rb +8 -75
- data/lib/active_record/turntable/algorithm/range_algorithm.rb +6 -7
- data/lib/active_record/turntable/algorithm/range_bsearch_algorithm.rb +6 -7
- data/lib/active_record/turntable/base.rb +2 -17
- data/lib/active_record/turntable/cluster_helper_methods.rb +7 -4
- data/lib/active_record/turntable/connection_proxy.rb +4 -2
- data/lib/active_record/turntable/migration.rb +3 -5
- data/lib/active_record/turntable/mixer.rb +20 -19
- data/lib/active_record/turntable/pool_proxy.rb +20 -14
- data/lib/active_record/turntable/query_cache.rb +1 -1
- data/lib/active_record/turntable/railties/databases.rake +12 -12
- data/lib/active_record/turntable/seq_shard.rb +1 -1
- data/lib/active_record/turntable/sequencer/barrage.rb +3 -2
- data/lib/active_record/turntable/sequencer.rb +33 -29
- data/lib/active_record/turntable/shard.rb +8 -8
- data/lib/active_record/turntable/sharding_condition.rb +14 -14
- data/lib/active_record/turntable/sql_tree_patch.rb +7 -3
- data/lib/active_record/turntable/util.rb +4 -2
- data/lib/active_record/turntable/version.rb +1 -1
- data/lib/active_record/turntable.rb +6 -5
- data/lib/activerecord-turntable.rb +1 -0
- metadata +120 -101
- data/lib/active_record/turntable/helpers/test_helper.rb +0 -25
- data/lib/active_record/turntable/helpers.rb +0 -9
- data/spec/active_record/turntable/active_record_ext/association_preloader_spec.rb +0 -78
- data/spec/active_record/turntable/active_record_ext/association_spec.rb +0 -81
- data/spec/active_record/turntable/active_record_ext/clever_load_spec.rb +0 -72
- data/spec/active_record/turntable/active_record_ext/fixture_set_spec.rb +0 -27
- data/spec/active_record/turntable/active_record_ext/locking_optimistic_spec.rb +0 -28
- data/spec/active_record/turntable/active_record_ext/migration_spec.rb +0 -38
- data/spec/active_record/turntable/active_record_ext/persistence_spec.rb +0 -211
- data/spec/active_record/turntable/active_record_ext/sequencer_spec.rb +0 -22
- data/spec/active_record/turntable/active_record_ext/test_fixtures_spec.rb +0 -34
- data/spec/active_record/turntable/algorithm/modulo_algorithm_spec.rb +0 -34
- data/spec/active_record/turntable/algorithm/range_algorithm_spec.rb +0 -34
- data/spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb +0 -34
- data/spec/active_record/turntable/algorithm_spec.rb +0 -100
- data/spec/active_record/turntable/base_spec.rb +0 -13
- data/spec/active_record/turntable/cluster_spec.rb +0 -48
- data/spec/active_record/turntable/config_spec.rb +0 -17
- data/spec/active_record/turntable/connection_proxy_spec.rb +0 -252
- data/spec/active_record/turntable/finder_spec.rb +0 -40
- data/spec/active_record/turntable/mixer/fader_spec.rb +0 -4
- data/spec/active_record/turntable/mixer_spec.rb +0 -112
- data/spec/active_record/turntable/query_cache_spec.rb +0 -28
- data/spec/active_record/turntable/sequencer/api_spec.rb +0 -38
- data/spec/active_record/turntable/sequencer/barrage_spec.rb +0 -22
- data/spec/active_record/turntable/sequencer/mysql_spec.rb +0 -22
- data/spec/active_record/turntable/shard_spec.rb +0 -21
- data/spec/active_record/turntable/sql_tree_patch_spec.rb +0 -34
- data/spec/active_record/turntable/transaction_spec.rb +0 -35
- data/spec/active_record/turntable_spec.rb +0 -30
- data/spec/config/database.yml +0 -35
- data/spec/config/turntable.yml +0 -56
- data/spec/fabricators/.gitkeep +0 -0
- data/spec/fabricators/turntable_fabricator.rb +0 -12
- data/spec/fixtures/cards.yml +0 -11
- data/spec/migrations/.gitkeep +0 -0
- data/spec/migrations/001_create_users.rb +0 -17
- data/spec/migrations/002_create_user_statuses.rb +0 -16
- data/spec/migrations/003_create_cards.rb +0 -14
- data/spec/migrations/004_create_cards_users.rb +0 -15
- data/spec/models/card.rb +0 -3
- data/spec/models/cards_user.rb +0 -10
- data/spec/models/cards_users_histories.rb +0 -7
- data/spec/models/events_users_history.rb +0 -7
- data/spec/models/user.rb +0 -7
- data/spec/models/user_status.rb +0 -6
- data/spec/spec_helper.rb +0 -38
- data/spec/support/matchers/be_saved_to.rb +0 -6
- data/spec/support/turntable_helper.rb +0 -30
data/spec/config/turntable.yml
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
test:
|
2
|
-
clusters:
|
3
|
-
user_cluster:
|
4
|
-
algorithm: range_bsearch
|
5
|
-
seq:
|
6
|
-
user_seq:
|
7
|
-
connection: turntable_user_seq_test
|
8
|
-
shards:
|
9
|
-
- connection: user_shard_1
|
10
|
-
less_than: 20000
|
11
|
-
- connection: user_shard_2
|
12
|
-
less_than: 40000
|
13
|
-
- connection: user_shard_1
|
14
|
-
less_than: 60000
|
15
|
-
- connection: user_shard_2
|
16
|
-
less_than: 80000
|
17
|
-
- connection: user_shard_3
|
18
|
-
less_than: 10000000
|
19
|
-
event_cluster:
|
20
|
-
algorithm: range_bsearch
|
21
|
-
seq:
|
22
|
-
user_seq:
|
23
|
-
connection: turntable_user_seq_test
|
24
|
-
shards:
|
25
|
-
- connection: user_shard_4
|
26
|
-
less_than: 20000
|
27
|
-
- connection: user_shard_5
|
28
|
-
less_than: 40000
|
29
|
-
- connection: user_shard_4
|
30
|
-
less_than: 60000
|
31
|
-
- connection: user_shard_5
|
32
|
-
less_than: 80000
|
33
|
-
- connection: user_shard_6
|
34
|
-
less_than: 10000000
|
35
|
-
mod_cluster:
|
36
|
-
algorithm: modulo
|
37
|
-
seq:
|
38
|
-
user_seq:
|
39
|
-
connection: turntable_user_seq_test
|
40
|
-
shards:
|
41
|
-
- connection: user_shard_1
|
42
|
-
- connection: user_shard_2
|
43
|
-
- connection: user_shard_1
|
44
|
-
- connection: user_shard_2
|
45
|
-
- connection: user_shard_3
|
46
|
-
mysql_mod_cluster:
|
47
|
-
algorithm: modulo
|
48
|
-
seq:
|
49
|
-
user_seq:
|
50
|
-
seq_type: mysql
|
51
|
-
connection: user_seq
|
52
|
-
shards:
|
53
|
-
- connection: user_shard_1
|
54
|
-
- connection: user_shard_2
|
55
|
-
- connection: user_shard_2
|
56
|
-
|
data/spec/fabricators/.gitkeep
DELETED
File without changes
|
data/spec/fixtures/cards.yml
DELETED
data/spec/migrations/.gitkeep
DELETED
File without changes
|
@@ -1,17 +0,0 @@
|
|
1
|
-
class CreateUsers < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
create_table :users do |t|
|
4
|
-
t.string :nickname
|
5
|
-
t.string :thumbnail_url
|
6
|
-
t.binary :blob
|
7
|
-
t.datetime :joined_at
|
8
|
-
t.datetime :deleted_at
|
9
|
-
|
10
|
-
t.timestamps
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.down
|
15
|
-
drop_table :users
|
16
|
-
end
|
17
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
class CreateUserStatuses < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
create_table :user_statuses do |t|
|
4
|
-
t.belongs_to :user, null: false
|
5
|
-
t.integer :hp, null: false, default: 0
|
6
|
-
t.integer :mp, null: false, default: 0
|
7
|
-
t.datetime :deleted_at, default: nil
|
8
|
-
|
9
|
-
t.timestamps
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.down
|
14
|
-
drop_table :user_statuses
|
15
|
-
end
|
16
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
class CreateCards < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
create_table :cards do |t|
|
4
|
-
t.string :name, null: false
|
5
|
-
t.integer :hp, null: false, default: 0
|
6
|
-
t.integer :mp, null: false, default: 0
|
7
|
-
t.timestamps
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.down
|
12
|
-
drop_table :cards
|
13
|
-
end
|
14
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
class CreateCardsUsers < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
create_table :cards_users do |t|
|
4
|
-
t.belongs_to :card, null: false
|
5
|
-
t.belongs_to :user, null: false
|
6
|
-
t.datetime :deleted_at
|
7
|
-
|
8
|
-
t.timestamps
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.down
|
13
|
-
drop_table :cards_users
|
14
|
-
end
|
15
|
-
end
|
data/spec/models/card.rb
DELETED
data/spec/models/cards_user.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
class CardsUser < ActiveRecord::Base
|
2
|
-
turntable :user_cluster, :user_id
|
3
|
-
sequencer :user_seq
|
4
|
-
|
5
|
-
belongs_to :user
|
6
|
-
belongs_to :card
|
7
|
-
has_many :cards_users_histories
|
8
|
-
has_many :events_users_histories
|
9
|
-
has_many :events_users_histories_with_foreign_shard_key, class_name: "EventsUsersHistory", foreign_shard_key: :user_id
|
10
|
-
end
|
data/spec/models/user.rb
DELETED
data/spec/models/user_status.rb
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
-
require "rubygems"
|
4
|
-
require "bundler/setup"
|
5
|
-
require "rspec/its"
|
6
|
-
require "rspec/collection_matchers"
|
7
|
-
require "webmock/rspec"
|
8
|
-
require "pry"
|
9
|
-
require "timecop"
|
10
|
-
begin
|
11
|
-
require "pry-byebug"
|
12
|
-
rescue LoadError
|
13
|
-
end
|
14
|
-
|
15
|
-
require "activerecord-turntable"
|
16
|
-
|
17
|
-
require "coveralls"
|
18
|
-
Coveralls.wear!
|
19
|
-
|
20
|
-
MIGRATIONS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), "migrations"))
|
21
|
-
|
22
|
-
# Requires supporting files with custom matchers and macros, etc,
|
23
|
-
# in ./support/ and its subdirectories.
|
24
|
-
ActiveRecord::Base.configurations = YAML.load_file(File.join(File.dirname(__FILE__), "config/database.yml"))
|
25
|
-
ActiveRecord::Base.establish_connection(:test)
|
26
|
-
|
27
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
28
|
-
|
29
|
-
RSpec.configure do |config|
|
30
|
-
include TurntableHelper
|
31
|
-
|
32
|
-
config.filter_run focus: true
|
33
|
-
config.run_all_when_everything_filtered = true
|
34
|
-
|
35
|
-
config.before(:each) do
|
36
|
-
Dir[File.join(File.dirname(File.dirname(__FILE__)), "spec/models/*.rb")].each { |f| require f }
|
37
|
-
end
|
38
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require "active_record"
|
2
|
-
|
3
|
-
module TurntableHelper
|
4
|
-
def reload_turntable!(config_file_name = nil)
|
5
|
-
ActiveRecord::Base.include(ActiveRecord::Turntable)
|
6
|
-
ActiveRecord::Base.turntable_config_file = config_file_name
|
7
|
-
ActiveRecord::Turntable::Config.load!(ActiveRecord::Base.turntable_config_file, :test)
|
8
|
-
end
|
9
|
-
|
10
|
-
def establish_connection_to(env = :test)
|
11
|
-
silence_warnings {
|
12
|
-
Object.const_set("RAILS_ENV", env.to_s)
|
13
|
-
Object.const_set("Rails", Object.new)
|
14
|
-
allow(Rails).to receive(:env) { ActiveSupport::StringInquirer.new(RAILS_ENV) }
|
15
|
-
ActiveRecord::Base.logger = Logger.new("/dev/null")
|
16
|
-
}
|
17
|
-
ActiveRecord::Base.establish_connection(env)
|
18
|
-
end
|
19
|
-
|
20
|
-
def truncate_shard
|
21
|
-
ActiveRecord::Base.descendants.each do |klass|
|
22
|
-
next if klass.abstract_class?
|
23
|
-
klass.delete_all
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def migrate(version)
|
28
|
-
ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT, version)
|
29
|
-
end
|
30
|
-
end
|