active_record_mysql_xverify 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.rubocop.yml +16 -0
- data/.travis.yml +25 -0
- data/Appraisals +16 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +81 -0
- data/LICENSE.txt +21 -0
- data/README.md +130 -0
- data/Rakefile +11 -0
- data/activerecord_mysql_xverify.gemspec +32 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docker-compose.yml +8 -0
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/ar42.gemfile +8 -0
- data/gemfiles/ar50.gemfile +7 -0
- data/gemfiles/ar51.gemfile +7 -0
- data/gemfiles/ar52.gemfile +7 -0
- data/lib/active_record_mysql_xverify.rb +17 -0
- data/lib/active_record_mysql_xverify/config.rb +33 -0
- data/lib/active_record_mysql_xverify/constants.rb +3 -0
- data/lib/active_record_mysql_xverify/error_handler.rb +14 -0
- data/lib/active_record_mysql_xverify/logger.rb +11 -0
- data/lib/active_record_mysql_xverify/utils.rb +16 -0
- data/lib/active_record_mysql_xverify/verifier.rb +36 -0
- data/lib/active_record_mysql_xverify/verifiers/aurora_master.rb +7 -0
- data/lib/active_record_mysql_xverify/version.rb +3 -0
- metadata +172 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8633a85faba0ec2354e9d7e0b458ca5b93af15ae13fae736ad823aad6c493b43
|
4
|
+
data.tar.gz: ab101f59d1c6d9e2a2211c4d62768ad86612b58c88f578f4c656bc3d83178293
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bd0857e1d6cc99d26d6e35bd1b33e1c3ff24fe535f635e2e2b76efc80d8edb93f4b6e638311bb011c64b54ed91edb6a0f4de11359c477817be7331528517d21d
|
7
|
+
data.tar.gz: edc43d517bb4c7b527ec82a5f662ec45c4618ab8684cd056f0a9f41338273dfd871b954fb33530497edec7078620a2808c028c626e251411254e5ac51ea7de73
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- 'gemfiles/**/*'
|
4
|
+
TargetRubyVersion: 2.2
|
5
|
+
Metrics/BlockLength:
|
6
|
+
Enabled: false
|
7
|
+
Metrics/LineLength:
|
8
|
+
Enabled: false
|
9
|
+
Metrics/MethodLength:
|
10
|
+
Enabled: false
|
11
|
+
Naming/UncommunicativeMethodParamName:
|
12
|
+
Enabled: false
|
13
|
+
Style/Documentation:
|
14
|
+
Enabled: false
|
15
|
+
Style/TrailingCommaInHashLiteral:
|
16
|
+
EnforcedStyleForMultiline: consistent_comma
|
data/.travis.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
---
|
2
|
+
dist: xenial
|
3
|
+
sudo: required
|
4
|
+
language: ruby
|
5
|
+
cache: bundler
|
6
|
+
rvm:
|
7
|
+
- 2.3.6
|
8
|
+
- 2.4.4
|
9
|
+
- 2.5.1
|
10
|
+
before_install:
|
11
|
+
- docker-compose up -d
|
12
|
+
- function mysql_ping { mysqladmin -u root -h 127.0.0.1 -P 6033 ping > /dev/null 2> /dev/null; }
|
13
|
+
- for i in {1..60}; do mysql_ping && break; sleep 1; done
|
14
|
+
script:
|
15
|
+
- bundle exec rake
|
16
|
+
gemfile:
|
17
|
+
- gemfiles/ar42.gemfile
|
18
|
+
- gemfiles/ar50.gemfile
|
19
|
+
- gemfiles/ar51.gemfile
|
20
|
+
- gemfiles/ar52.gemfile
|
21
|
+
addons:
|
22
|
+
apt:
|
23
|
+
packages:
|
24
|
+
- mysql-client-core-5.7
|
25
|
+
- mysql-client-5.7
|
data/Appraisals
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
appraise 'ar42' do
|
2
|
+
gem 'activerecord', '~> 4.2.10'
|
3
|
+
gem 'mysql2', '< 0.5'
|
4
|
+
end
|
5
|
+
|
6
|
+
appraise 'ar50' do
|
7
|
+
gem 'activerecord', '~> 5.0.7'
|
8
|
+
end
|
9
|
+
|
10
|
+
appraise 'ar51' do
|
11
|
+
gem 'activerecord', '~> 5.1.6'
|
12
|
+
end
|
13
|
+
|
14
|
+
appraise 'ar52' do
|
15
|
+
gem 'activerecord', '~> 5.2.1'
|
16
|
+
end
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
active_record_mysql_xverify (0.1.0)
|
5
|
+
activerecord
|
6
|
+
mysql2
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (5.2.1)
|
12
|
+
activesupport (= 5.2.1)
|
13
|
+
activerecord (5.2.1)
|
14
|
+
activemodel (= 5.2.1)
|
15
|
+
activesupport (= 5.2.1)
|
16
|
+
arel (>= 9.0)
|
17
|
+
activesupport (5.2.1)
|
18
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
|
+
i18n (>= 0.7, < 2)
|
20
|
+
minitest (~> 5.1)
|
21
|
+
tzinfo (~> 1.1)
|
22
|
+
appraisal (2.2.0)
|
23
|
+
bundler
|
24
|
+
rake
|
25
|
+
thor (>= 0.14.0)
|
26
|
+
arel (9.0.0)
|
27
|
+
ast (2.4.0)
|
28
|
+
concurrent-ruby (1.1.3)
|
29
|
+
diff-lcs (1.3)
|
30
|
+
i18n (1.1.1)
|
31
|
+
concurrent-ruby (~> 1.0)
|
32
|
+
jaro_winkler (1.5.1)
|
33
|
+
minitest (5.11.3)
|
34
|
+
mysql2 (0.5.2)
|
35
|
+
parallel (1.12.1)
|
36
|
+
parser (2.5.3.0)
|
37
|
+
ast (~> 2.4.0)
|
38
|
+
powerpack (0.1.2)
|
39
|
+
rainbow (3.0.0)
|
40
|
+
rake (10.5.0)
|
41
|
+
rspec (3.8.0)
|
42
|
+
rspec-core (~> 3.8.0)
|
43
|
+
rspec-expectations (~> 3.8.0)
|
44
|
+
rspec-mocks (~> 3.8.0)
|
45
|
+
rspec-core (3.8.0)
|
46
|
+
rspec-support (~> 3.8.0)
|
47
|
+
rspec-expectations (3.8.2)
|
48
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
+
rspec-support (~> 3.8.0)
|
50
|
+
rspec-mocks (3.8.0)
|
51
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
+
rspec-support (~> 3.8.0)
|
53
|
+
rspec-support (3.8.0)
|
54
|
+
rubocop (0.60.0)
|
55
|
+
jaro_winkler (~> 1.5.1)
|
56
|
+
parallel (~> 1.10)
|
57
|
+
parser (>= 2.5, != 2.5.1.1)
|
58
|
+
powerpack (~> 0.1)
|
59
|
+
rainbow (>= 2.2.2, < 4.0)
|
60
|
+
ruby-progressbar (~> 1.7)
|
61
|
+
unicode-display_width (~> 1.4.0)
|
62
|
+
ruby-progressbar (1.10.0)
|
63
|
+
thor (0.20.0)
|
64
|
+
thread_safe (0.3.6)
|
65
|
+
tzinfo (1.2.5)
|
66
|
+
thread_safe (~> 0.1)
|
67
|
+
unicode-display_width (1.4.0)
|
68
|
+
|
69
|
+
PLATFORMS
|
70
|
+
ruby
|
71
|
+
|
72
|
+
DEPENDENCIES
|
73
|
+
active_record_mysql_xverify!
|
74
|
+
appraisal
|
75
|
+
bundler
|
76
|
+
rake
|
77
|
+
rspec (~> 3.0)
|
78
|
+
rubocop
|
79
|
+
|
80
|
+
BUNDLED WITH
|
81
|
+
1.17.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 winebarrel
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
# active_record_mysql_xverify
|
2
|
+
|
3
|
+
It is a library that performs extended verification when an error occurs when executing SQL.
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/active_record_mysql_xverify.svg)](http://badge.fury.io/rb/active_record_mysql_xverify)
|
6
|
+
[![Build Status](https://travis-ci.org/winebarrel/active_record_mysql_xverify.svg?branch=master)](https://travis-ci.org/winebarrel/active_record_mysql_xverify)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'active_record_mysql_xverify'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install active_record_mysql_xverify
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
#!/usr/bin/env ruby
|
28
|
+
require 'active_record'
|
29
|
+
require 'active_record_mysql_xverify'
|
30
|
+
require 'logger'
|
31
|
+
|
32
|
+
ActiveRecord::Base.establish_connection(
|
33
|
+
adapter: 'mysql2',
|
34
|
+
host: '127.0.0.1',
|
35
|
+
username: 'root',
|
36
|
+
database: 'bookshelf',
|
37
|
+
)
|
38
|
+
|
39
|
+
ActiveRecord::Base.logger = Logger.new($stdout)
|
40
|
+
ActiveRecord::Base.logger.formatter = proc {|_, _, _, message| "#{message}\n" }
|
41
|
+
|
42
|
+
ActiveRecordMysqlXverify.verify = ->(conn) do
|
43
|
+
conn.ping && false # force reconnect
|
44
|
+
end
|
45
|
+
# Default: ->(conn) { conn.ping }
|
46
|
+
|
47
|
+
ActiveRecordMysqlXverify.handle_if = ->(config) do
|
48
|
+
config[:host] == '127.0.0.1'
|
49
|
+
end
|
50
|
+
# Default: ->(_) { true }
|
51
|
+
|
52
|
+
ActiveRecordMysqlXverify.only_on_error = false
|
53
|
+
# Default: true
|
54
|
+
|
55
|
+
# CREATE DATABASE IF NOT EXISTS bookshelf;
|
56
|
+
# CREATE TABLE bookshelf.books (id INT PRIMARY KEY);
|
57
|
+
class Book < ActiveRecord::Base; end
|
58
|
+
|
59
|
+
Book.count
|
60
|
+
prev_thread_id = Book.connection.raw_connection.thread_id
|
61
|
+
|
62
|
+
ActiveRecord::Base.connection_handler.connection_pool_list.each(&:release_connection)
|
63
|
+
|
64
|
+
Book.count
|
65
|
+
curr_thread_id = Book.connection.raw_connection.thread_id
|
66
|
+
|
67
|
+
p curr_thread_id == prev_thread_id #=> false
|
68
|
+
```
|
69
|
+
|
70
|
+
|
71
|
+
## Rails configuration
|
72
|
+
|
73
|
+
In `config/environments/production.rb`:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
ActiveRecordMysqlXverify.verify = ->(conn) do
|
77
|
+
conn.ping && conn.query('show variables like "innodb_read_only"').first.fetch(1) == 'OFF'
|
78
|
+
end
|
79
|
+
# Same as below:
|
80
|
+
# ActiveRecordMysqlXverify.verify = ActiveRecordMysqlXverify::Verifiers::AURORA_MASTER
|
81
|
+
```
|
82
|
+
|
83
|
+
## Rails log example
|
84
|
+
|
85
|
+
```
|
86
|
+
Started PATCH "/items/1" for 127.0.0.1 at 2018-11-15 15:47:31 +0900
|
87
|
+
Processing by ItemsController#update as */*
|
88
|
+
Parameters: {"utf8"=>"✓", "authenticity_token"=>"...", "item"=>{"name"=>"1", "price"=>"1", "time"=>"1542264451"}, "commit"=>"Update Item", "id"=>"1"}
|
89
|
+
Item Load (26.6ms) SELECT `items`.* FROM `items` WHERE `items`.`id` = 1 LIMIT 1
|
90
|
+
Completed 500 Internal Server Error in 136ms (ActiveRecord: 131.3ms)
|
91
|
+
ActiveRecord::StatementInvalid (Mysql2::Error: MySQL client is not connected: ROLLBACK):
|
92
|
+
|
93
|
+
...
|
94
|
+
|
95
|
+
Mysql2::Error::ConnectionError (Can't connect to MySQL server on 'my-cluster.cluster-xxx.ap-northeast-1.rds.amazonaws.com' (61)):
|
96
|
+
|
97
|
+
...
|
98
|
+
|
99
|
+
Started PATCH "/items/1" for 127.0.0.1 at 2018-11-15 15:47:35 +0900
|
100
|
+
Processing by ItemsController#update as */*
|
101
|
+
Parameters: {"utf8"=>"✓", "authenticity_token"=>"...", "item"=>{"name"=>"1", "price"=>"1", "time"=>"1542264454"}, "commit"=>"Update Item", "id"=>"1"}
|
102
|
+
SQL (27.8ms) UPDATE `items` SET `time` = '1542264454', `updated_at` = '2018-11-15 06:47:35' WHERE `items`.`id` = 1
|
103
|
+
Completed 500 Internal Server Error in 134ms (ActiveRecord: 126.9ms)
|
104
|
+
ActiveRecord::StatementInvalid (Mysql2::Error: The MySQL server is running with the --read-only option so it cannot execute this statement: UPDATE `items` SET `time` = '1542264454', `updated_at` = '2018-11-15 06:47:35' WHERE `items`.`id` = 1):
|
105
|
+
|
106
|
+
...
|
107
|
+
|
108
|
+
Started PATCH "/items/1" for 127.0.0.1 at 2018-11-15 15:47:36 +0900
|
109
|
+
Invalid connection: host=my-cluster.cluster-xxx.ap-northeast-1.rds.amazonaws.com, database=my_production_db, username=scott, thread_id=4
|
110
|
+
Processing by ItemsController#update as */*
|
111
|
+
Parameters: {"utf8"=>"✓", "authenticity_token"=>"...", "item"=>{"name"=>"1", "price"=>"1", "time"=>"1542264456"}, "commit"=>"Update Item", "id"=>"1"}
|
112
|
+
SQL (35.8ms) UPDATE `items` SET `time` = '1542264456', `updated_at` = '2018-11-15 06:47:37' WHERE `items`.`id` = 1
|
113
|
+
Completed 500 Internal Server Error in 145ms (ActiveRecord: 140.8ms)
|
114
|
+
ActiveRecord::StatementInvalid (Mysql2::Error: The MySQL server is running with the --read-only option so it cannot execute this statement: UPDATE `items` SET `time` = '1542264456', `updated_at` = '2018-11-15 06:47:37' WHERE `items`.`id` = 1):
|
115
|
+
|
116
|
+
...
|
117
|
+
...
|
118
|
+
...
|
119
|
+
|
120
|
+
Started PATCH "/items/1" for 127.0.0.1 at 2018-11-15 15:47:49 +0900
|
121
|
+
Invalid connection: host=my-cluster.cluster-xxx.ap-northeast-1.rds.amazonaws.com, database=my_production_db, username=scott, thread_id=11
|
122
|
+
Processing by ItemsController#update as */*
|
123
|
+
Parameters: {"utf8"=>"✓", "authenticity_token"=>"...", "item"=>{"name"=>"1", "price"=>"1", "time"=>"1542264469"}, "commit"=>"Update Item", "id"=>"1"}
|
124
|
+
Item Load (44.6ms) SELECT `items`.* FROM `items` WHERE `items`.`id` = 1 LIMIT 1
|
125
|
+
(36.5ms) BEGIN
|
126
|
+
SQL (29.5ms) UPDATE `items` SET `time` = '1542264469', `updated_at` = '2018-11-15 06:47:50' WHERE `items`.`id` = 1
|
127
|
+
(34.5ms) COMMIT
|
128
|
+
Redirected to http://localhost:3000/items/1
|
129
|
+
Completed 302 Found in 150ms (ActiveRecord: 145.2ms)
|
130
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'active_record_mysql_xverify/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'active_record_mysql_xverify'
|
7
|
+
spec.version = ActiveRecordMysqlXverify::VERSION
|
8
|
+
spec.authors = ['winebarrel']
|
9
|
+
spec.email = ['sugawara@winebarrel.jp']
|
10
|
+
|
11
|
+
spec.summary = 'It is a library that performs extended verification when an error occurs when executing SQL.'
|
12
|
+
spec.description = 'It is a library that performs extended verification when an error occurs when executing SQL.'
|
13
|
+
spec.homepage = 'https://github.com/winebarrel/active_record_mysql_xverify'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_dependency 'activerecord'
|
26
|
+
spec.add_dependency 'mysql2'
|
27
|
+
spec.add_development_dependency 'appraisal'
|
28
|
+
spec.add_development_dependency 'bundler'
|
29
|
+
spec.add_development_dependency 'rake'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
31
|
+
spec.add_development_dependency 'rubocop'
|
32
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'activerecord_mysql_xverify'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/docker-compose.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'active_support'
|
3
|
+
require 'active_record_mysql_xverify/version'
|
4
|
+
require 'active_record_mysql_xverify/constants'
|
5
|
+
require 'active_record_mysql_xverify/logger'
|
6
|
+
require 'active_record_mysql_xverify/utils'
|
7
|
+
require 'active_record_mysql_xverify/config'
|
8
|
+
require 'active_record_mysql_xverify/error_handler'
|
9
|
+
require 'active_record_mysql_xverify/verifier'
|
10
|
+
require 'active_record_mysql_xverify/verifiers/aurora_master'
|
11
|
+
|
12
|
+
ActiveSupport.on_load :active_record do
|
13
|
+
require 'active_record/connection_adapters/abstract_mysql_adapter'
|
14
|
+
require 'active_record/connection_adapters/mysql2_adapter'
|
15
|
+
ActiveRecord::ConnectionAdapters::Mysql2Adapter.prepend ActiveRecordMysqlXverify::ErrorHandler
|
16
|
+
ActiveRecord::ConnectionAdapters::Mysql2Adapter.prepend ActiveRecordMysqlXverify::Verifier
|
17
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ActiveRecordMysqlXverify
|
2
|
+
@config = {
|
3
|
+
handle_if: ->(_) { true },
|
4
|
+
verify: ->(conn) { conn.ping },
|
5
|
+
only_on_error: true,
|
6
|
+
}
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def handle_if=(proc)
|
10
|
+
@config[:handle_if] = proc
|
11
|
+
end
|
12
|
+
|
13
|
+
def handle_if
|
14
|
+
@config.fetch(:handle_if)
|
15
|
+
end
|
16
|
+
|
17
|
+
def verify=(proc)
|
18
|
+
@config[:verify] = proc
|
19
|
+
end
|
20
|
+
|
21
|
+
def verify
|
22
|
+
@config.fetch(:verify)
|
23
|
+
end
|
24
|
+
|
25
|
+
def only_on_error=(bool)
|
26
|
+
@config[:only_on_error] = bool
|
27
|
+
end
|
28
|
+
|
29
|
+
def only_on_error
|
30
|
+
@config.fetch(:only_on_error)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ActiveRecordMysqlXverify
|
2
|
+
module ErrorHandler
|
3
|
+
def execute(*)
|
4
|
+
super
|
5
|
+
rescue StandardError
|
6
|
+
_flag_extend_verify!
|
7
|
+
raise
|
8
|
+
end
|
9
|
+
|
10
|
+
def _flag_extend_verify!
|
11
|
+
Thread.current[ActiveRecordMysqlXverify::EXTEND_VERIFY_FLAG] = true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ActiveRecordMysqlXverify
|
2
|
+
module Utils
|
3
|
+
class << self
|
4
|
+
def mysql2_connection_info(conn)
|
5
|
+
thread_id = begin
|
6
|
+
conn.thread_id
|
7
|
+
rescue StandardError
|
8
|
+
nil
|
9
|
+
end
|
10
|
+
|
11
|
+
"host=#{conn.query_options[:host]}, database=#{conn.query_options[:database]}, " \
|
12
|
+
"username=#{conn.query_options[:username]}, thread_id=#{thread_id}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ActiveRecordMysqlXverify
|
2
|
+
module Verifier
|
3
|
+
def active?
|
4
|
+
if _extend_verify?
|
5
|
+
is_active = begin
|
6
|
+
verifier = ActiveRecordMysqlXverify.verify
|
7
|
+
verifier.call(@connection)
|
8
|
+
rescue StandardError => e
|
9
|
+
ActiveRecordMysqlXverify.logger.warn("Connection verification failed: #{_build_verify_error_message(e)}")
|
10
|
+
false
|
11
|
+
ensure
|
12
|
+
Thread.current[ActiveRecordMysqlXverify::EXTEND_VERIFY_FLAG] = false
|
13
|
+
end
|
14
|
+
|
15
|
+
unless is_active
|
16
|
+
ActiveRecordMysqlXverify.logger.info(
|
17
|
+
"Invalid connection: #{ActiveRecordMysqlXverify::Utils.mysql2_connection_info(@connection)}"
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
is_active
|
22
|
+
else
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def _build_verify_error_message(e)
|
28
|
+
"cause: #{e.message} [#{e.class}, " + ActiveRecordMysqlXverify::Utils.mysql2_connection_info(@connection)
|
29
|
+
end
|
30
|
+
|
31
|
+
def _extend_verify?
|
32
|
+
handle_if = ActiveRecordMysqlXverify.handle_if
|
33
|
+
(Thread.current[ActiveRecordMysqlXverify::EXTEND_VERIFY_FLAG] || !ActiveRecordMysqlXverify.only_on_error) && handle_if.call(@config)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_record_mysql_xverify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- winebarrel
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mysql2
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: appraisal
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: It is a library that performs extended verification when an error occurs
|
112
|
+
when executing SQL.
|
113
|
+
email:
|
114
|
+
- sugawara@winebarrel.jp
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".rubocop.yml"
|
122
|
+
- ".travis.yml"
|
123
|
+
- Appraisals
|
124
|
+
- Gemfile
|
125
|
+
- Gemfile.lock
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- activerecord_mysql_xverify.gemspec
|
130
|
+
- bin/console
|
131
|
+
- bin/setup
|
132
|
+
- docker-compose.yml
|
133
|
+
- gemfiles/.bundle/config
|
134
|
+
- gemfiles/ar42.gemfile
|
135
|
+
- gemfiles/ar50.gemfile
|
136
|
+
- gemfiles/ar51.gemfile
|
137
|
+
- gemfiles/ar52.gemfile
|
138
|
+
- lib/active_record_mysql_xverify.rb
|
139
|
+
- lib/active_record_mysql_xverify/config.rb
|
140
|
+
- lib/active_record_mysql_xverify/constants.rb
|
141
|
+
- lib/active_record_mysql_xverify/error_handler.rb
|
142
|
+
- lib/active_record_mysql_xverify/logger.rb
|
143
|
+
- lib/active_record_mysql_xverify/utils.rb
|
144
|
+
- lib/active_record_mysql_xverify/verifier.rb
|
145
|
+
- lib/active_record_mysql_xverify/verifiers/aurora_master.rb
|
146
|
+
- lib/active_record_mysql_xverify/version.rb
|
147
|
+
homepage: https://github.com/winebarrel/active_record_mysql_xverify
|
148
|
+
licenses:
|
149
|
+
- MIT
|
150
|
+
metadata: {}
|
151
|
+
post_install_message:
|
152
|
+
rdoc_options: []
|
153
|
+
require_paths:
|
154
|
+
- lib
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
requirements: []
|
166
|
+
rubyforge_project:
|
167
|
+
rubygems_version: 2.7.6
|
168
|
+
signing_key:
|
169
|
+
specification_version: 4
|
170
|
+
summary: It is a library that performs extended verification when an error occurs
|
171
|
+
when executing SQL.
|
172
|
+
test_files: []
|