Skip to content

Commit

Permalink
Merge branch 'develop-3-0' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
gussan committed Feb 17, 2017
2 parents 281dc73 + 985a75f commit 58ffda1
Show file tree
Hide file tree
Showing 108 changed files with 1,604 additions and 1,680 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "tmp/rails"]
path = tmp/rails
url = https://github.com/rails/rails.git
14 changes: 14 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
inherit_gem:
onkcop:
- "config/rubocop.yml"
- "config/rspec.yml"

inherit_from:
- ".rubocop_todo.yml"

AllCops:
TargetRubyVersion: 2.2
Exclude:
- "test/**/*"
- "tmp/**/*"
- "activerecord.rake"
152 changes: 152 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-02-10 00:09:09 +0900 using RuboCop version 0.47.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
# Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition:
Exclude:
- 'lib/active_record/turntable/active_record_ext/connection_handler_extension.rb'
- 'lib/active_record/turntable/active_record_ext/schema_dumper.rb'

# Offense count: 4
Lint/RescueException:
Exclude:
- 'lib/active_record/turntable/connection_proxy.rb'
- 'lib/active_record/turntable/mixer.rb'

# Offense count: 5
# Cop supports --auto-correct.
Lint/UnneededSplatExpansion:
Exclude:
- 'Rakefile'

# Offense count: 14
Metrics/AbcSize:
Max: 106

# Offense count: 2
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 88

# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 202

# Offense count: 5
Metrics/CyclomaticComplexity:
Max: 20

# Offense count: 2
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 246

# Offense count: 10
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 56

# Offense count: 1
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
Max: 6

# Offense count: 9
Metrics/PerceivedComplexity:
Max: 24

# Offense count: 3
# Cop supports --auto-correct.
Performance/TimesMap:
Exclude:
- 'script/performance/algorithm'
- 'spec/active_record/turntable/active_record_ext/association_preloader_spec.rb'
- 'spec/active_record/turntable/active_record_ext/association_spec.rb'

# Offense count: 1
# Configuration parameters: CustomIncludeMethods.
RSpec/EmptyExampleGroup:
Exclude:
- 'spec/active_record/turntable/mixer/fader_spec.rb'

# Offense count: 3
# Configuration parameters: CustomTransform, IgnoreMethods.
RSpec/FilePath:
Exclude:
- 'spec/active_record/turntable/active_record_ext/fixture_set_spec.rb'
- 'spec/active_record/turntable/active_record_ext/test_fixtures_spec.rb'

# Offense count: 21
# Configuration parameters: Max.
RSpec/NestedGroups:
Exclude:
- 'spec/active_record/turntable/active_record_ext/association_preloader_spec.rb'
- 'spec/active_record/turntable/active_record_ext/association_spec.rb'
- 'spec/active_record/turntable/active_record_ext/clever_load_spec.rb'
- 'spec/active_record/turntable/connection_proxy_spec.rb'
- 'spec/active_record/turntable/finder_spec.rb'
- 'spec/active_record/turntable/mixer_spec.rb'

# Offense count: 15
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
# FunctionalMethods: let, let!, subject, watch
# IgnoredMethods: lambda, proc, it
Style/BlockDelimiters:
Exclude:
- 'spec/**/*'
- 'lib/active_record/turntable/active_record_ext/acts_as_archive_extension.rb'
- 'lib/active_record/turntable/active_record_ext/clever_load.rb'
- 'lib/active_record/turntable/active_record_ext/database_tasks.rb'
- 'lib/active_record/turntable/active_record_ext/fixtures.rb'
- 'lib/active_record/turntable/algorithm/range_bsearch_algorithm.rb'
- 'lib/active_record/turntable/cluster_helper_methods.rb'
- 'lib/active_record/turntable/connection_proxy.rb'
- 'script/performance/algorithm'

# Offense count: 2
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'lib/active_record/turntable/sql_tree_patch.rb'

# Offense count: 4
Style/MethodCalledOnDoEndBlock:
Exclude:
- 'lib/active_record/turntable/migration.rb'
- 'lib/active_record/turntable/mixer.rb'
- 'lib/active_record/turntable/mixer/fader/update_shards_merge_result.rb'
- 'lib/active_record/turntable/sql_tree_patch.rb'

# Offense count: 5
# Cop supports --auto-correct.
# Configuration parameters: PreferredDelimiters.
Style/PercentLiteralDelimiters:
Exclude:
- 'Rakefile'

# Offense count: 6
# Cop supports --auto-correct.
# Configuration parameters: AllowMultipleReturnValues.
Style/RedundantReturn:
Exclude:
- 'lib/active_record/turntable/sql_tree_patch.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowSafeAssignment.
# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex
Style/TernaryParentheses:
Exclude:
- 'lib/active_record/turntable/sequencer.rb'
- 'lib/active_record/turntable/sql_tree_patch.rb'
33 changes: 23 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
language: ruby
sudo: false

cache:
bundler: true

rvm:
- 2.0.0
- 2.1
- 2.2
- 2.2.6
- 2.3.3
- 2.4.0
- ruby-head

gemfile:
- gemfiles/rails4_0.gemfile
- gemfiles/rails4_1.gemfile
- gemfiles/rails4_2.gemfile
- gemfiles/rails5_0.gemfile
- gemfiles/rails_edge.gemfile

env:
- SETUP_TASK=turntable:db:reset BUILD_TASK=spec
- SETUP_TASK=turntable:activerecord:setup BUILD_TASK=turntable:activerecord:test

before_install: gem update --system

before_script:
- bundle exec rake turntable:db:reset
script: bundle exec rake spec
- bundle exec rake $SETUP_TASK

script:
- bundle exec rake $BUILD_TASK

matrix:
allow_failures:
- rvm: ruby-head
sudo: false
cache: bundler
- gemfile: gemfiles/rails_edge.gemfile
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
## activerecord-turntable 3.0.0.alpha3 ##

### Bugfix

* Disable statement cache when adding shard conditions automatically

## activerecord-turntable 3.0.0.alpha2 ##

### Improvement

* Fix to propagate shard conditions to `AssociationRelation` too

## activerecord-turntable 3.0.0.alpha1 ##

### Major Changes

* Rails5 compatibility
* Minimum ruby requirement version is `2.2.2`
* Rails 4.x support has been dropped.

## activerecord-turntable 2.5.0 ##

### Improvement
Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
source "https://rubygems.org"

gemspec

gem "activerecord", "~> 5.0.1"
gem "activesupport", "~> 5.0.1"
19 changes: 12 additions & 7 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard 'rspec',
cmd: "bundle exec rspec",
all_after_pass: true,
all_on_start: true do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
guard "rspec",
cmd: "bundle exec rspec",
all_after_pass: true,
all_on_start: true do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch("spec/spec_helper.rb") { "spec" }
end

guard :rubocop do
watch(/.+\.rb$/)
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
end
30 changes: 11 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ ActiveRecord::Turntable is a database sharding extension for ActiveRecord.

## Dependencies

activerecord(>=4.0.0)
activerecord(>=5.0.0, <6.0)

if you are using activerecord 3.x, please use activerecord-turntable version 1.x.
If you are using with older activerecord versions, use following versions.

* activerecord 4.x - use activerecord-turntable version 2.x.([stable-2-x branch](https://github.com/drecom/activerecord-turntable/tree/stable-2-x))
* activerecord 3.x - use activerecord-turntable version 1.x.([stable-1-x branch](https://github.com/drecom/activerecord-turntable/tree/stable-1-x))

## Supported Database

Expand All @@ -22,7 +25,7 @@ Currently supports mysql only.
Add to Gemfile:

```ruby
gem 'activerecord-turntable', '~> 2.1.1'
gem 'activerecord-turntable', '~> 3.0.0.alpha1'
```

Run a bundle install:
Expand Down Expand Up @@ -136,7 +139,7 @@ Edit turntable.yml and database.yml. See below example config.
database: sample_app_user3_development
```

### Example Migration
### Example Migration

Generate a model:

Expand Down Expand Up @@ -282,7 +285,7 @@ First, add configuration to turntable.yml and database.yml
seq:
user_seq: # <-- sequencer name
seq_type: mysql # <-- sequencer type
connection: user_seq_1 # <-- sequencer database connection
connection: user_seq_1 # <-- sequencer database connection
```

Add below to the migration:
Expand Down Expand Up @@ -369,8 +372,8 @@ end
transaction helper to execute transaction to all shards in the cluster:

```ruby
User.user_cluster_transaction do
# Transaction is opened all shards in "user_cluster"
User.user_cluster_transaction do
# Transaction is opened all shards in "user_cluster"
end
```

Expand Down Expand Up @@ -432,23 +435,12 @@ Use with_all method:
end
```

### Connection Management

Rails's ConnectionManagement middleware keeps ActiveRecord's connection during the process is alive, but Turntable keeps more connections.
This may cause flooding max connections on your database. So, we made a middleware that disconnects on each request.

if you use turntable's ConnectionManagement middleware, add below line to your initializer.

```ruby
app.middleware.swap ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::Turntable::Rack::ConnectionManagement
```

### Performance Exception

To notice queries causing performance problem, Turntable has follow options.

* raise\_on\_not\_specified\_shard\_query - raises on queries execute on all shards
* raise\_on\_not\_specified\_shard\_update - raises on updates executed on all shards
* raise\_on\_not\_specified\_shard\_update - raises on updates executed on all shards


Add to turntable.yml:
Expand Down

0 comments on commit 58ffda1

Please sign in to comment.