activerecord-turntable 3.0.0.alpha3 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +3 -0
  3. data/.rubocop.yml +18 -0
  4. data/.rubocop_todo.yml +153 -0
  5. data/.travis.yml +20 -4
  6. data/CHANGELOG.md +32 -0
  7. data/Guardfile +2 -2
  8. data/README.md +68 -14
  9. data/Rakefile +42 -0
  10. data/activerecord-turntable.gemspec +13 -3
  11. data/gemfiles/rails_edge.gemfile +8 -0
  12. data/lib/active_record/turntable/active_record_ext/abstract_adapter.rb +3 -1
  13. data/lib/active_record/turntable/active_record_ext/activerecord_import_ext.rb +5 -7
  14. data/lib/active_record/turntable/active_record_ext/acts_as_archive_extension.rb +2 -2
  15. data/lib/active_record/turntable/active_record_ext/association.rb +3 -3
  16. data/lib/active_record/turntable/active_record_ext/clever_load.rb +2 -2
  17. data/lib/active_record/turntable/active_record_ext/database_tasks.rb +10 -8
  18. data/lib/active_record/turntable/active_record_ext/fixtures.rb +15 -13
  19. data/lib/active_record/turntable/active_record_ext/log_subscriber.rb +6 -0
  20. data/lib/active_record/turntable/active_record_ext/persistence.rb +25 -23
  21. data/lib/active_record/turntable/active_record_ext/schema_dumper.rb +8 -75
  22. data/lib/active_record/turntable/algorithm/range_algorithm.rb +6 -7
  23. data/lib/active_record/turntable/algorithm/range_bsearch_algorithm.rb +6 -7
  24. data/lib/active_record/turntable/base.rb +2 -17
  25. data/lib/active_record/turntable/cluster_helper_methods.rb +7 -4
  26. data/lib/active_record/turntable/connection_proxy.rb +4 -2
  27. data/lib/active_record/turntable/migration.rb +3 -5
  28. data/lib/active_record/turntable/mixer.rb +20 -19
  29. data/lib/active_record/turntable/pool_proxy.rb +20 -14
  30. data/lib/active_record/turntable/query_cache.rb +1 -1
  31. data/lib/active_record/turntable/railties/databases.rake +12 -12
  32. data/lib/active_record/turntable/seq_shard.rb +1 -1
  33. data/lib/active_record/turntable/sequencer/barrage.rb +3 -2
  34. data/lib/active_record/turntable/sequencer.rb +33 -29
  35. data/lib/active_record/turntable/shard.rb +8 -8
  36. data/lib/active_record/turntable/sharding_condition.rb +14 -14
  37. data/lib/active_record/turntable/sql_tree_patch.rb +7 -3
  38. data/lib/active_record/turntable/util.rb +4 -2
  39. data/lib/active_record/turntable/version.rb +1 -1
  40. data/lib/active_record/turntable.rb +6 -5
  41. data/lib/activerecord-turntable.rb +1 -0
  42. metadata +120 -101
  43. data/lib/active_record/turntable/helpers/test_helper.rb +0 -25
  44. data/lib/active_record/turntable/helpers.rb +0 -9
  45. data/spec/active_record/turntable/active_record_ext/association_preloader_spec.rb +0 -78
  46. data/spec/active_record/turntable/active_record_ext/association_spec.rb +0 -81
  47. data/spec/active_record/turntable/active_record_ext/clever_load_spec.rb +0 -72
  48. data/spec/active_record/turntable/active_record_ext/fixture_set_spec.rb +0 -27
  49. data/spec/active_record/turntable/active_record_ext/locking_optimistic_spec.rb +0 -28
  50. data/spec/active_record/turntable/active_record_ext/migration_spec.rb +0 -38
  51. data/spec/active_record/turntable/active_record_ext/persistence_spec.rb +0 -211
  52. data/spec/active_record/turntable/active_record_ext/sequencer_spec.rb +0 -22
  53. data/spec/active_record/turntable/active_record_ext/test_fixtures_spec.rb +0 -34
  54. data/spec/active_record/turntable/algorithm/modulo_algorithm_spec.rb +0 -34
  55. data/spec/active_record/turntable/algorithm/range_algorithm_spec.rb +0 -34
  56. data/spec/active_record/turntable/algorithm/range_bsearch_algorithm_spec.rb +0 -34
  57. data/spec/active_record/turntable/algorithm_spec.rb +0 -100
  58. data/spec/active_record/turntable/base_spec.rb +0 -13
  59. data/spec/active_record/turntable/cluster_spec.rb +0 -48
  60. data/spec/active_record/turntable/config_spec.rb +0 -17
  61. data/spec/active_record/turntable/connection_proxy_spec.rb +0 -252
  62. data/spec/active_record/turntable/finder_spec.rb +0 -40
  63. data/spec/active_record/turntable/mixer/fader_spec.rb +0 -4
  64. data/spec/active_record/turntable/mixer_spec.rb +0 -112
  65. data/spec/active_record/turntable/query_cache_spec.rb +0 -28
  66. data/spec/active_record/turntable/sequencer/api_spec.rb +0 -38
  67. data/spec/active_record/turntable/sequencer/barrage_spec.rb +0 -22
  68. data/spec/active_record/turntable/sequencer/mysql_spec.rb +0 -22
  69. data/spec/active_record/turntable/shard_spec.rb +0 -21
  70. data/spec/active_record/turntable/sql_tree_patch_spec.rb +0 -34
  71. data/spec/active_record/turntable/transaction_spec.rb +0 -35
  72. data/spec/active_record/turntable_spec.rb +0 -30
  73. data/spec/config/database.yml +0 -35
  74. data/spec/config/turntable.yml +0 -56
  75. data/spec/fabricators/.gitkeep +0 -0
  76. data/spec/fabricators/turntable_fabricator.rb +0 -12
  77. data/spec/fixtures/cards.yml +0 -11
  78. data/spec/migrations/.gitkeep +0 -0
  79. data/spec/migrations/001_create_users.rb +0 -17
  80. data/spec/migrations/002_create_user_statuses.rb +0 -16
  81. data/spec/migrations/003_create_cards.rb +0 -14
  82. data/spec/migrations/004_create_cards_users.rb +0 -15
  83. data/spec/models/card.rb +0 -3
  84. data/spec/models/cards_user.rb +0 -10
  85. data/spec/models/cards_users_histories.rb +0 -7
  86. data/spec/models/events_users_history.rb +0 -7
  87. data/spec/models/user.rb +0 -7
  88. data/spec/models/user_status.rb +0 -6
  89. data/spec/spec_helper.rb +0 -38
  90. data/spec/support/matchers/be_saved_to.rb +0 -6
  91. data/spec/support/turntable_helper.rb +0 -30
@@ -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
-
File without changes
@@ -1,12 +0,0 @@
1
- # load models
2
-
3
- # Fabrication
4
- Fabricator(:user_status) do
5
- hp { (0..10).to_a.sample }
6
- mp { (0..10).to_a.sample }
7
- end
8
-
9
- Fabricator(:user) do
10
- nickname { Faker::Name.name }
11
- user_status { Fabricator(:user_status) }
12
- end
@@ -1,11 +0,0 @@
1
- card_1:
2
- id: 1
3
- name: card_1
4
- hp: 10
5
- mp: 10
6
-
7
- card_2:
8
- id: 2
9
- name: card_2
10
- hp: 20
11
- mp: 20
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
@@ -1,3 +0,0 @@
1
- class Card < ActiveRecord::Base
2
- belongs_to :cards_user
3
- end
@@ -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
@@ -1,7 +0,0 @@
1
- class CardsUsersHistory < ActiveRecord::Base
2
- turntable :user_cluster, :user_id
3
- sequencer :user_seq
4
-
5
- belongs_to :user
6
- belongs_to :cards_user
7
- end
@@ -1,7 +0,0 @@
1
- class EventsUsersHistory < ActiveRecord::Base
2
- turntable :event_cluster, :events_user_id
3
- sequencer :user_seq
4
-
5
- belongs_to :user
6
- belongs_to :cards_user
7
- end
data/spec/models/user.rb DELETED
@@ -1,7 +0,0 @@
1
- class User < ActiveRecord::Base
2
- # shard by surrogate_key
3
- turntable :user_cluster, :id
4
- sequencer :user_seq
5
- has_one :user_status
6
- has_many :cards_users
7
- end
@@ -1,6 +0,0 @@
1
- class UserStatus < ActiveRecord::Base
2
- # shard by other key
3
- turntable :user_cluster, :user_id
4
- sequencer :user_seq
5
- belongs_to :user
6
- end
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,6 +0,0 @@
1
- RSpec::Matchers.define :be_saved_to do |shard|
2
- match do |actual|
3
- persisted_actual = actual.with_shard(shard) { actual.class.find(actual.id) }
4
- persisted_actual && actual == persisted_actual
5
- end
6
- 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