knockoff 1.1.0.alpha → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b9352faddb2bf60d2ddf6f3c91c9e03bce498a41
4
- data.tar.gz: c4bb57f7a8b240d71ca164d489de9b26535ce53b
2
+ SHA256:
3
+ metadata.gz: 22fb5337ef43e286ab938ab8d6e4905529607979266b8bb7673eccdba23c5d3c
4
+ data.tar.gz: 9990634bf328df85fe419cbb3aea20b591d4a9c94420184f89012a15649ac2af
5
5
  SHA512:
6
- metadata.gz: 13d2338a6425fe9eea71c30b8b838f7df6fe9c69e369193b67bd3be59c739062a8f0515f7cc28c2846e0df743d9745467b5e3b5e3cf2bfdbeb680719c2bc4efd
7
- data.tar.gz: ffda5a9534ca24f6dfb85d59ea3a225bd5759a50eaa94f71ae869396abf7d7806fa05583108adfbd240abb0c5356b2d9b3bf241af0dc0f59fb3c0edeab906d1a
6
+ metadata.gz: d7e7d9f11f4a7ea199d48e98c322d66b75db01eb2659b5218ea3928c586e1cab1d4087e3c7eb2aa1c54bdce744beb4f5c46fd2e4b43dc3972c1d735c6762acbf
7
+ data.tar.gz: 4a6d620cffa48322560e060e1b500704791216d9daf6a3f6f81e90adaec25546012dbf0a55ca66c427265b87f42d3f0a1818f2aa93fbb84292a89ff7cd816bd2
@@ -0,0 +1,24 @@
1
+ name: Ruby
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ test:
7
+
8
+ runs-on: ubuntu-20.04
9
+
10
+ strategy:
11
+ matrix:
12
+ ruby-version: ['2.4.0', '2.5.1', '2.6.6', '2.7.2']
13
+
14
+ steps:
15
+ # Pin to this commit: v2
16
+ - uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
17
+ - name: Set up Ruby
18
+ # Lock to this commit, v1.82.0
19
+ uses: ruby/setup-ruby@5e4f0a10bfc39c97cd5358121291e27e5d97e09b
20
+ with:
21
+ ruby-version: ${{ matrix.ruby-version }}
22
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
23
+ - name: Run tests
24
+ run: bundle exec rake spec
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 1.1.1
4
+
5
+ - Drop Ruby 2.3 support
6
+ - Add Ruby 2.6 and 2.7 support
7
+ - Fix a deprecation warning in Rails 6
8
+
9
+ ## 1.1.0
10
+
3
11
  - Allow for not checking `inside_transaction?` on primary database (https://github.com/joinhandshake/knockoff/pull/13)
4
12
  - Allow setting `Knockoff.default_target` to set the default target other than `:primary` (https://github.com/joinhandshake/knockoff/pull/11)
5
13
  - Drop Ruby 2.2 support
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Knockoff
2
2
 
3
- [![Build Status](https://travis-ci.org/joinhandshake/knockoff.svg?branch=master)](https://travis-ci.org/joinhandshake/knockoff)
3
+ [![Build Status](https://github.com/joinhandshake/knockoff/actions/workflows/ruby.yml/badge.svg)](https://github.com/joinhandshake/knockoff/actions)
4
4
  [![Gem Version](https://badge.fury.io/rb/knockoff.svg)](https://badge.fury.io/rb/knockoff)
5
5
 
6
6
  A gem for easily using read replicas.
7
7
 
8
- :handshake: Battle tested at [Handshake](https://joinhandshake.com/engineering/)
8
+ :handshake: Battle tested at [Handshake](https://joinhandshake.com/)
9
9
 
10
10
  ## Library Goals
11
11
 
@@ -17,7 +17,7 @@ A gem for easily using read replicas.
17
17
 
18
18
  ## Supported Versions
19
19
 
20
- Knockoff supports Rails 4 and 5
20
+ Knockoff supports Rails 4, 5 and 6
21
21
 
22
22
  ## Installation
23
23
 
data/knockoff.gemspec CHANGED
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency 'activerecord', '>= 4.0.0'
22
- spec.add_runtime_dependency 'activesupport', '>= 4.0.0'
21
+ spec.add_runtime_dependency 'activerecord', '>= 4.0.0', '< 6.1'
22
+ spec.add_runtime_dependency 'activesupport', '>= 4.0.0', '< 6.1'
23
23
 
24
24
  spec.add_development_dependency "bundler"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
@@ -5,11 +5,11 @@ module ActiveRecord
5
5
  # Supports queries like User.on_replica.to_a
6
6
  alias_method :exec_queries_without_knockoff, :exec_queries
7
7
 
8
- def exec_queries
8
+ def exec_queries(&block)
9
9
  if knockoff_target == :replica
10
- Knockoff.on_replica { exec_queries_without_knockoff }
10
+ Knockoff.on_replica { exec_queries_without_knockoff(&block) }
11
11
  else
12
- exec_queries_without_knockoff
12
+ exec_queries_without_knockoff(&block)
13
13
  end
14
14
  end
15
15
 
@@ -95,11 +95,24 @@ module Knockoff
95
95
  end
96
96
 
97
97
  # Store the hash in configuration and use it when we establish the connection later.
98
+ # TODO: In ActiveRecord >= 6, this is a deprecated way to set a configuration. However
99
+ # there appears to be an issue when calling `ActiveRecord::Base.configurations.to_h` in
100
+ # version 6.0.4.8 where
101
+ # multi-database setup is being ignored / dropped. For example if a database.yml setup
102
+ # has something like..
103
+ #
104
+ # development:
105
+ # primary:
106
+ # ...
107
+ # other:
108
+ # ...
109
+ #
110
+ # then the 'other' database configuration is being dropped.
98
111
  key = "knockoff_replica_#{index}"
99
- full_config = replica_config.merge(uri_config)
112
+ config = replica_config.merge(uri_config)
113
+ ActiveRecord::Base.configurations[key] = config
100
114
 
101
- ActiveRecord::Base.configurations[key] = full_config
102
- @replicas_configurations[key] = full_config
115
+ @replicas_configurations[key] = config
103
116
  rescue URI::InvalidURIError
104
117
  Rails.logger.info "LOG NOTIFIER: Invalid URL specified in follower_env_keys. Not including URI, which may result in no followers used." # URI is purposely not printed to logs
105
118
  # Return a 'nil' which will be removed from
@@ -30,6 +30,12 @@ module Knockoff
30
30
  end
31
31
  end
32
32
 
33
+ def set_schema_cache(cache)
34
+ @pool.each do |_name, klass|
35
+ klass.connection_pool.schema_cache = cache
36
+ end
37
+ end
38
+
33
39
  def random_replica_connection
34
40
  @pool[@pool.keys.sample]
35
41
  end
@@ -1,3 +1,3 @@
1
1
  module Knockoff
2
- VERSION = '1.1.0.alpha'.freeze
2
+ VERSION = '1.3.0'.freeze
3
3
  end
data/lib/knockoff.rb CHANGED
@@ -49,6 +49,10 @@ module Knockoff
49
49
  @config ||= Config.new
50
50
  end
51
51
 
52
+ def set_schema_cache(cache)
53
+ replica_pool.set_schema_cache(cache)
54
+ end
55
+
52
56
  def base_transaction_depth
53
57
  @base_transaction_depth ||= begin
54
58
  testcase = ActiveSupport::TestCase
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knockoff
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0.alpha
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Ringwelski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-26 00:00:00.000000000 Z
11
+ date: 2022-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 4.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6.1'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: 4.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.1'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: activesupport
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -31,6 +37,9 @@ dependencies:
31
37
  - - ">="
32
38
  - !ruby/object:Gem::Version
33
39
  version: 4.0.0
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '6.1'
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -38,6 +47,9 @@ dependencies:
38
47
  - - ">="
39
48
  - !ruby/object:Gem::Version
40
49
  version: 4.0.0
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '6.1'
41
53
  - !ruby/object:Gem::Dependency
42
54
  name: bundler
43
55
  requirement: !ruby/object:Gem::Requirement
@@ -101,9 +113,10 @@ executables: []
101
113
  extensions: []
102
114
  extra_rdoc_files: []
103
115
  files:
116
+ - ".github/workflows/ruby.yml"
104
117
  - ".gitignore"
105
118
  - ".rspec"
106
- - ".travis.yml"
119
+ - ".ruby-version"
107
120
  - CHANGELOG.md
108
121
  - Gemfile
109
122
  - LICENSE.txt
@@ -136,12 +149,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
149
  version: '0'
137
150
  required_rubygems_version: !ruby/object:Gem::Requirement
138
151
  requirements:
139
- - - ">"
152
+ - - ">="
140
153
  - !ruby/object:Gem::Version
141
- version: 1.3.1
154
+ version: '0'
142
155
  requirements: []
143
- rubyforge_project:
144
- rubygems_version: 2.6.13
156
+ rubygems_version: 3.1.4
145
157
  signing_key:
146
158
  specification_version: 4
147
159
  summary: A gem for easily using read replicas
data/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- language: ruby
2
- notifications:
3
- email: false
4
- rvm:
5
- - 2.3.1
6
- - 2.4.0
7
- - 2.5.1
8
- - ruby-head