standby 4.0.0 → 5.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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +23 -0
- data/.gitignore +1 -4
- data/README.md +4 -7
- data/gemfiles/rails4.2.gemfile +5 -1
- data/gemfiles/rails5.2.gemfile +5 -0
- data/gemfiles/rails7.0.gemfile +5 -0
- data/lib/standby/active_record/log_subscriber.rb +10 -1
- data/lib/standby/active_record/relation.rb +13 -12
- data/lib/standby/connection_holder.rb +9 -3
- data/lib/standby/version.rb +7 -1
- data/spec/configuration_spec.rb +17 -3
- data/spec/spec_helper.rb +5 -4
- data/spec/{slavery_spec.rb → standby_spec.rb} +6 -0
- data/standby.gemspec +3 -1
- metadata +32 -14
- data/.travis.yml +0 -13
- data/gemfiles/rails3.2.gemfile +0 -9
- data/gemfiles/rails4.gemfile +0 -5
- data/slavery.gemspec +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b43e6971bad583281f150be7a768115af32883b72bdd42c16ee9b885c33b070
|
4
|
+
data.tar.gz: a6574d223d15071d3143dadcf3977edb82227c5b5455a55129e5887c4c097e16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5298e4882873365eb18a25a92e393547c9587d40e5acd70cdd25c87503d1d77ba713dab54ec826c4a675958c2aa2beb6dd31dd61da105c679712d884f981f9b9
|
7
|
+
data.tar.gz: 13cd75e347a2abbaa974e1f761422d6f2ad33d0cacd01c462a9e8d9e61f66febb47f87b6edcef89aefe3ec57c82b80291f79d83c50bb7c49b1139917d565e41c
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: ci
|
2
|
+
on: [pull_request, push]
|
3
|
+
|
4
|
+
jobs:
|
5
|
+
test:
|
6
|
+
strategy:
|
7
|
+
fail-fast: false
|
8
|
+
matrix:
|
9
|
+
ruby:
|
10
|
+
- "2.7"
|
11
|
+
rails_version:
|
12
|
+
- "7.0"
|
13
|
+
- "5.2"
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
env:
|
16
|
+
BUNDLE_GEMFILE: gemfiles/rails${{ matrix.rails_version }}.gemfile
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v3
|
19
|
+
- uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: ${{ matrix.ruby }}
|
22
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
23
|
+
- run: bundle exec rake
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Standby - Read from standby databases for ActiveRecord (formerly Slavery)
|
2
2
|
|
3
|
-
|
3
|
+

|
4
4
|
|
5
5
|
Standby is a simple, easy to use gem for ActiveRecord that enables conservative reading from standby databases, which means it won't automatically redirect all SELECTs to standbys.
|
6
6
|
|
@@ -155,13 +155,10 @@ Update your Gemfile
|
|
155
155
|
gem 'standby'
|
156
156
|
```
|
157
157
|
|
158
|
-
|
158
|
+
Then
|
159
159
|
|
160
|
-
|
161
|
-
|
162
|
-
grep -e on_slave **/*.rake **/*.rb -s -l | xargs sed -i "" "s|on_slave|on_standby|g"
|
163
|
-
grep -e on_master **/*.rake **/*.rb -s -l | xargs sed -i "" "s|on_master|on_primary|g"
|
164
|
-
```
|
160
|
+
* Replace `Slavery` with `Standby`, `on_slave` with `on_standby`, and `on_master` with `on_primary`
|
161
|
+
* Update keys in `database.yml` (e.g. `development_slave` to `development_standby`)
|
165
162
|
|
166
163
|
## Upgrading from version 2 to version 3
|
167
164
|
|
data/gemfiles/rails4.2.gemfile
CHANGED
@@ -1,12 +1,21 @@
|
|
1
|
+
require 'standby/version'
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
class LogSubscriber
|
3
5
|
|
4
6
|
alias_method :debug_without_standby, :debug
|
5
7
|
|
6
8
|
def debug(msg)
|
7
|
-
db = Standby.disabled ?
|
9
|
+
db = Standby.disabled ? '' : log_header
|
8
10
|
debug_without_standby(db + msg)
|
9
11
|
end
|
10
12
|
|
13
|
+
def log_header
|
14
|
+
if Standby.version_gte?('7.1')
|
15
|
+
color("[#{Thread.current[:_standby] || "primary"}]", ActiveSupport::LogSubscriber::GREEN, bold: true)
|
16
|
+
else
|
17
|
+
color("[#{Thread.current[:_standby] || "primary"}]", ActiveSupport::LogSubscriber::GREEN, true)
|
18
|
+
end
|
19
|
+
end
|
11
20
|
end
|
12
21
|
end
|
@@ -1,19 +1,18 @@
|
|
1
|
+
module ExecQueriesWithStandbyTarget
|
2
|
+
# Supports queries like User.on_standby.to_a
|
3
|
+
def exec_queries
|
4
|
+
if standby_target
|
5
|
+
Standby.on_standby(standby_target) { super }
|
6
|
+
else
|
7
|
+
super
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
1
12
|
module ActiveRecord
|
2
13
|
class Relation
|
3
14
|
attr_accessor :standby_target
|
4
15
|
|
5
|
-
# Supports queries like User.on_standby.to_a
|
6
|
-
alias_method :exec_queries_without_standby, :exec_queries
|
7
|
-
|
8
|
-
def exec_queries
|
9
|
-
if standby_target
|
10
|
-
Standby.on_standby(standby_target) { exec_queries_without_standby }
|
11
|
-
else
|
12
|
-
exec_queries_without_standby
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
16
|
# Supports queries like User.on_standby.count
|
18
17
|
alias_method :calculate_without_standby, :calculate
|
19
18
|
|
@@ -26,3 +25,5 @@ module ActiveRecord
|
|
26
25
|
end
|
27
26
|
end
|
28
27
|
end
|
28
|
+
|
29
|
+
ActiveRecord::Relation.prepend(ExecQueriesWithStandbyTarget)
|
@@ -5,8 +5,14 @@ module Standby
|
|
5
5
|
class << self
|
6
6
|
# for delayed activation
|
7
7
|
def activate(target)
|
8
|
-
|
9
|
-
|
8
|
+
env_name = "#{ActiveRecord::ConnectionHandling::RAILS_ENV.call}_#{target}"
|
9
|
+
if Standby.version_gte?('7.0')
|
10
|
+
spec = ActiveRecord::Base.configurations.find_db_config(env_name)&.configuration_hash
|
11
|
+
else
|
12
|
+
spec = ActiveRecord::Base.configurations[env_name]
|
13
|
+
end
|
14
|
+
raise Error, "Standby target '#{target}' is invalid!" if spec.nil?
|
15
|
+
|
10
16
|
establish_connection spec
|
11
17
|
end
|
12
18
|
end
|
@@ -25,4 +31,4 @@ module Standby
|
|
25
31
|
end
|
26
32
|
end
|
27
33
|
end
|
28
|
-
end
|
34
|
+
end
|
data/lib/standby/version.rb
CHANGED
data/spec/configuration_spec.rb
CHANGED
@@ -4,7 +4,13 @@ describe 'configuration' do
|
|
4
4
|
before do
|
5
5
|
# Backup connection and configs
|
6
6
|
@backup_conn = Standby.instance_variable_get :@standby_connections
|
7
|
-
|
7
|
+
if Standby.version_gte?('7.0')
|
8
|
+
@backup_config = ActiveRecord::Base.configurations.configs_for.map do |config|
|
9
|
+
[config.env_name, config.configuration_hash]
|
10
|
+
end.to_h
|
11
|
+
else
|
12
|
+
@backup_config = ActiveRecord::Base.configurations.dup
|
13
|
+
end
|
8
14
|
@backup_disabled = Standby.disabled
|
9
15
|
@backup_conn.each_key do |klass_name|
|
10
16
|
Object.send(:remove_const, klass_name) if Object.const_defined?(klass_name)
|
@@ -20,13 +26,21 @@ describe 'configuration' do
|
|
20
26
|
end
|
21
27
|
|
22
28
|
it 'raises error if standby configuration not specified' do
|
23
|
-
|
29
|
+
if Standby.version_gte?('7.0')
|
30
|
+
ActiveRecord::Base.configurations = @backup_config.merge({ 'test_standby' => {} })
|
31
|
+
else
|
32
|
+
ActiveRecord::Base.configurations['test_standby'] = nil
|
33
|
+
end
|
24
34
|
|
25
35
|
expect { Standby.on_standby { User.count } }.to raise_error(Standby::Error)
|
26
36
|
end
|
27
37
|
|
28
38
|
it 'connects to primary if standby configuration is disabled' do
|
29
|
-
|
39
|
+
if Standby.version_gte?('7.0')
|
40
|
+
ActiveRecord::Base.configurations = @backup_config.merge({ 'test_standby' => {} })
|
41
|
+
else
|
42
|
+
ActiveRecord::Base.configurations['test_standby'] = nil
|
43
|
+
end
|
30
44
|
Standby.disabled = true
|
31
45
|
|
32
46
|
expect(Standby.on_standby { User.count }).to be 2
|
data/spec/spec_helper.rb
CHANGED
@@ -6,19 +6,20 @@ ENV['RACK_ENV'] = 'test'
|
|
6
6
|
require 'standby'
|
7
7
|
|
8
8
|
ActiveRecord::Base.configurations = {
|
9
|
-
'test' => { 'adapter' => 'sqlite3', 'database' => 'test_db' },
|
10
|
-
'test_standby' => { 'adapter' => 'sqlite3', 'database' => 'test_standby_one' },
|
11
|
-
'test_standby_two' => { 'adapter' => 'sqlite3', 'database' => 'test_standby_two'},
|
9
|
+
'test' => { 'adapter' => 'sqlite3', 'database' => 'spec/db/test_db' },
|
10
|
+
'test_standby' => { 'adapter' => 'sqlite3', 'database' => 'spec/db/test_standby_one' },
|
11
|
+
'test_standby_two' => { 'adapter' => 'sqlite3', 'database' => 'spec/db/test_standby_two'},
|
12
12
|
'test_standby_url' => 'postgres://root:@localhost:5432/test_standby'
|
13
13
|
}
|
14
14
|
|
15
15
|
# Prepare databases
|
16
16
|
class User < ActiveRecord::Base
|
17
17
|
has_many :items
|
18
|
+
attr_accessor :name
|
18
19
|
end
|
19
20
|
|
20
21
|
class Item < ActiveRecord::Base
|
21
|
-
belongs_to :user
|
22
|
+
belongs_to :user, inverse_of: :items
|
22
23
|
end
|
23
24
|
|
24
25
|
class Seeder
|
@@ -104,4 +104,10 @@ describe Standby do
|
|
104
104
|
expect(User.on_standby(:two).where(nil).to_a.size).to be 0
|
105
105
|
expect(User.on_standby.where(nil).to_a.size).to be 1
|
106
106
|
end
|
107
|
+
|
108
|
+
it 'does not interfere with setting inverses' do
|
109
|
+
user = User.first
|
110
|
+
user.update(name: 'a different name')
|
111
|
+
expect(user.items.first.user.name).to eq('a different name')
|
112
|
+
end
|
107
113
|
end
|
data/standby.gemspec
CHANGED
@@ -16,9 +16,11 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.executables = gem.files.grep(%r{^exe/}).map{ |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ['lib']
|
19
|
+
gem.required_ruby_version = '>= 2.0'
|
19
20
|
|
20
|
-
gem.add_runtime_dependency 'activerecord', '>= 3.0.0'
|
21
|
+
gem.add_runtime_dependency 'activerecord', '>= 3.0.0', '< 8.0'
|
21
22
|
|
23
|
+
gem.add_development_dependency 'rake'
|
22
24
|
gem.add_development_dependency 'rspec'
|
23
25
|
gem.add_development_dependency 'sqlite3'
|
24
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: standby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenn Ejima
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-11-04 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: 3.0.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '8.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +27,23 @@ dependencies:
|
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 3.0.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '8.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
48
|
name: rspec
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,17 +79,17 @@ executables: []
|
|
59
79
|
extensions: []
|
60
80
|
extra_rdoc_files: []
|
61
81
|
files:
|
82
|
+
- ".github/workflows/ci.yml"
|
62
83
|
- ".gitignore"
|
63
84
|
- ".rspec"
|
64
|
-
- ".travis.yml"
|
65
85
|
- Gemfile
|
66
86
|
- LICENSE.txt
|
67
87
|
- README.md
|
68
88
|
- Rakefile
|
69
89
|
- bin/console
|
70
|
-
- gemfiles/rails3.2.gemfile
|
71
90
|
- gemfiles/rails4.2.gemfile
|
72
|
-
- gemfiles/
|
91
|
+
- gemfiles/rails5.2.gemfile
|
92
|
+
- gemfiles/rails7.0.gemfile
|
73
93
|
- lib/standby.rb
|
74
94
|
- lib/standby/active_record/base.rb
|
75
95
|
- lib/standby/active_record/connection_handling.rb
|
@@ -80,16 +100,15 @@ files:
|
|
80
100
|
- lib/standby/error.rb
|
81
101
|
- lib/standby/transaction.rb
|
82
102
|
- lib/standby/version.rb
|
83
|
-
- slavery.gemspec
|
84
103
|
- spec/active_record/log_subscriber_spec.rb
|
85
104
|
- spec/configuration_spec.rb
|
86
|
-
- spec/slavery_spec.rb
|
87
105
|
- spec/spec_helper.rb
|
106
|
+
- spec/standby_spec.rb
|
88
107
|
- standby.gemspec
|
89
108
|
homepage: https://github.com/kenn/standby
|
90
109
|
licenses: []
|
91
110
|
metadata: {}
|
92
|
-
post_install_message:
|
111
|
+
post_install_message:
|
93
112
|
rdoc_options: []
|
94
113
|
require_paths:
|
95
114
|
- lib
|
@@ -97,20 +116,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
116
|
requirements:
|
98
117
|
- - ">="
|
99
118
|
- !ruby/object:Gem::Version
|
100
|
-
version: '0'
|
119
|
+
version: '2.0'
|
101
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
121
|
requirements:
|
103
122
|
- - ">="
|
104
123
|
- !ruby/object:Gem::Version
|
105
124
|
version: '0'
|
106
125
|
requirements: []
|
107
|
-
|
108
|
-
|
109
|
-
signing_key:
|
126
|
+
rubygems_version: 3.1.4
|
127
|
+
signing_key:
|
110
128
|
specification_version: 4
|
111
129
|
summary: Read from stand-by databases for ActiveRecord
|
112
130
|
test_files:
|
113
131
|
- spec/active_record/log_subscriber_spec.rb
|
114
132
|
- spec/configuration_spec.rb
|
115
|
-
- spec/slavery_spec.rb
|
116
133
|
- spec/spec_helper.rb
|
134
|
+
- spec/standby_spec.rb
|
data/.travis.yml
DELETED
data/gemfiles/rails3.2.gemfile
DELETED
data/gemfiles/rails4.gemfile
DELETED
data/slavery.gemspec
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'standby/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |gem|
|
7
|
-
gem.post_install_message = 'The slavery gem has been deprecated and has ' \
|
8
|
-
'been replaced by standby. Please switch to ' \
|
9
|
-
'standby as soon as possible.'
|
10
|
-
gem.name = 'slavery'
|
11
|
-
gem.version = Standby::VERSION
|
12
|
-
gem.authors = ['Kenn Ejima']
|
13
|
-
gem.email = ['kenn.ejima@gmail.com']
|
14
|
-
gem.description = %q{Simple, conservative slave reads for ActiveRecord}
|
15
|
-
gem.summary = %q{Simple, conservative slave reads for ActiveRecord}
|
16
|
-
gem.homepage = 'https://github.com/kenn/slavery'
|
17
|
-
|
18
|
-
gem.files = `git ls-files`.split($/)
|
19
|
-
gem.executables = gem.files.grep(%r{^exe/}).map{ |f| File.basename(f) }
|
20
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
21
|
-
gem.require_paths = ['lib']
|
22
|
-
|
23
|
-
gem.add_runtime_dependency 'activerecord', '>= 3.0.0'
|
24
|
-
|
25
|
-
gem.add_development_dependency 'rspec'
|
26
|
-
gem.add_development_dependency 'sqlite3'
|
27
|
-
end
|