active_record_mysql_xverify 0.1.1 → 0.2.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
2
  SHA256:
3
- metadata.gz: 2b9b9ce1ade186050ccfa538360ab9e4f05309b65a2d2fcc6e5d70532b95bf4e
4
- data.tar.gz: 5eebab1a79aa13eb7dbc8d2c697495ca4dac550ceda70046698b7c89b6891f69
3
+ metadata.gz: 247cfa1e88c414475aedb0a0da825d5860bfa0bac37557ff7c635fb7dec70ea8
4
+ data.tar.gz: e5a2e3ecf2448e82d8cbd5cdaae403f37ce780b4e0ab4edea5f620a37ba27731
5
5
  SHA512:
6
- metadata.gz: 783496ec07fe44f10c594a901cd46364add2257d4cee9cc4fc195567b54c28c0d5caf5d775f945d2e3f793a80e377b1bd64136b9080cb939c5cf34e3c9a7f861
7
- data.tar.gz: e5b1a46379a954bc2bbc7a220237d283a5a40b0328caec95edcb026a1052c5d76be52213b6a3bbb9338b30c6a846b8a54657013cab66e60290af81b2a22c4895
6
+ metadata.gz: b140b35801f33cc584ba71283329a7ac79eeacd7b5db5ccc217b6a903b254d3a64f0a03138a3a437f44f7d23d9b0c8b6555274f2a0b710c6929ff0aaa92aa106
7
+ data.tar.gz: ae7d6b6d69c781ff0558d47d8f62e39d1f524585ee7bf31ae912b38f6eaeccabc81e13272ed5971986412590ab9b5259da5b12208bdfdad8ab0b95ad2be7b4b9
@@ -1,16 +1,93 @@
1
1
  AllCops:
2
2
  Exclude:
3
- - 'gemfiles/**/*'
4
- TargetRubyVersion: 2.3
3
+ - "gemfiles/**/*"
4
+ TargetRubyVersion: 2.4
5
5
  Metrics/BlockLength:
6
6
  Enabled: false
7
7
  Metrics/LineLength:
8
8
  Enabled: false
9
9
  Metrics/MethodLength:
10
10
  Enabled: false
11
- Naming/UncommunicativeMethodParamName:
11
+ Naming/MethodParameterName:
12
12
  Enabled: false
13
13
  Style/Documentation:
14
14
  Enabled: false
15
15
  Style/TrailingCommaInHashLiteral:
16
16
  EnforcedStyleForMultiline: consistent_comma
17
+ Gemspec/RequiredRubyVersion:
18
+ Enabled: false
19
+
20
+ Layout/EmptyLinesAroundAttributeAccessor:
21
+ Enabled: true
22
+ Layout/SpaceAroundMethodCallOperator:
23
+ Enabled: true
24
+ Lint/BinaryOperatorWithIdenticalOperands:
25
+ Enabled: true
26
+ Lint/DeprecatedOpenSSLConstant:
27
+ Enabled: true
28
+ Lint/DuplicateElsifCondition:
29
+ Enabled: true
30
+ Lint/DuplicateRescueException:
31
+ Enabled: true
32
+ Lint/EmptyConditionalBody:
33
+ Enabled: true
34
+ Lint/FloatComparison:
35
+ Enabled: true
36
+ Lint/MissingSuper:
37
+ Enabled: true
38
+ Lint/MixedRegexpCaptureTypes:
39
+ Enabled: true
40
+ Lint/OutOfRangeRegexpRef:
41
+ Enabled: true
42
+ Lint/RaiseException:
43
+ Enabled: true
44
+ Lint/SelfAssignment:
45
+ Enabled: true
46
+ Lint/StructNewOverride:
47
+ Enabled: true
48
+ Lint/TopLevelReturnWithArgument:
49
+ Enabled: true
50
+ Lint/UnreachableLoop:
51
+ Enabled: true
52
+ Style/AccessorGrouping:
53
+ Enabled: true
54
+ Style/ArrayCoercion:
55
+ Enabled: true
56
+ Style/BisectedAttrAccessor:
57
+ Enabled: true
58
+ Style/CaseLikeIf:
59
+ Enabled: true
60
+ Style/ExplicitBlockArgument:
61
+ Enabled: true
62
+ Style/ExponentialNotation:
63
+ Enabled: true
64
+ Style/GlobalStdStream:
65
+ Enabled: true
66
+ Style/HashAsLastArrayItem:
67
+ Enabled: true
68
+ Style/HashEachMethods:
69
+ Enabled: true
70
+ Style/HashLikeCase:
71
+ Enabled: true
72
+ Style/HashTransformKeys:
73
+ Enabled: true
74
+ Style/HashTransformValues:
75
+ Enabled: true
76
+ Style/OptionalBooleanParameter:
77
+ Enabled: true
78
+ Style/RedundantAssignment:
79
+ Enabled: true
80
+ Style/RedundantFetchBlock:
81
+ Enabled: true
82
+ Style/RedundantFileExtensionInRequire:
83
+ Enabled: true
84
+ Style/RedundantRegexpCharacterClass:
85
+ Enabled: true
86
+ Style/RedundantRegexpEscape:
87
+ Enabled: true
88
+ Style/SingleArgumentDig:
89
+ Enabled: true
90
+ Style/SlicingWithRange:
91
+ Enabled: true
92
+ Style/StringConcatenation:
93
+ Enabled: true
@@ -1,17 +1,14 @@
1
1
  ---
2
- dist: xenial
3
- sudo: required
4
2
  language: ruby
5
3
  cache: bundler
6
4
  rvm:
7
- - 2.3.8
8
- - 2.4.6
9
- - 2.5.3
10
- - 2.6.3
5
+ - 2.5.8
6
+ - 2.6.6
7
+ - 2.7.1
8
+ env:
9
+ - DATABASE_HOST=localhost DATABASE_USER=travis
11
10
  before_install:
12
- - docker-compose up -d
13
- - function mysql_ping { mysqladmin -u root -h 127.0.0.1 -P 6033 ping > /dev/null 2> /dev/null; }
14
- - for i in {1..60}; do mysql_ping && break; sleep 1; done
11
+ - for i in {1..60}; do mysqladmin -u travis ping && break; sleep 1; done
15
12
  script:
16
13
  - bundle exec rake
17
14
  gemfile:
@@ -19,8 +16,10 @@ gemfile:
19
16
  - gemfiles/ar50.gemfile
20
17
  - gemfiles/ar51.gemfile
21
18
  - gemfiles/ar52.gemfile
22
- addons:
23
- apt:
24
- packages:
25
- - mysql-client-core-5.7
26
- - mysql-client-5.7
19
+ - gemfiles/ar60.gemfile
20
+ services:
21
+ - mysql
22
+ jobs:
23
+ exclude:
24
+ - rvm: 2.7.1
25
+ gemfile: gemfiles/ar42.gemfile
data/Appraisals CHANGED
@@ -16,3 +16,7 @@ end
16
16
  appraise 'ar52' do
17
17
  gem 'activerecord', '~> 5.2.1'
18
18
  end
19
+
20
+ appraise 'ar60' do
21
+ gem 'activerecord', '~> 6.0.3'
22
+ end
@@ -0,0 +1,13 @@
1
+ FROM rubylang/ruby:2.5-bionic
2
+
3
+ RUN apt-get update && \
4
+ apt-get install -y \
5
+ mysql-client \
6
+ libmysqlclient-dev \
7
+ rubygems
8
+
9
+ COPY ./ /mnt/
10
+ WORKDIR /mnt
11
+ RUN gem update bundler -f && \
12
+ bundle install && \
13
+ bundle exec appraisal install
data/README.md CHANGED
@@ -1,10 +1,18 @@
1
1
  # active_record_mysql_xverify
2
2
 
3
- It is a library that performs extended verification when an error occurs when executing SQL.
3
+ It is a library to solve Amazon RDS failover problems.
4
+
5
+ cf. https://github.com/brianmario/mysql2/issues/948
6
+
7
+ **Note: This library does not retry queries. Just reconnect.**
4
8
 
5
9
  [![Gem Version](https://badge.fury.io/rb/active_record_mysql_xverify.svg)](http://badge.fury.io/rb/active_record_mysql_xverify)
6
10
  [![Build Status](https://travis-ci.org/winebarrel/active_record_mysql_xverify.svg?branch=master)](https://travis-ci.org/winebarrel/active_record_mysql_xverify)
7
11
 
12
+ ## How it works
13
+
14
+ ![](https://user-images.githubusercontent.com/117768/59007604-19a61c80-8862-11e9-9f4b-515527b33ded.png)
15
+
8
16
  ## Installation
9
17
 
10
18
  Add this line to your application's Gemfile:
@@ -49,9 +57,6 @@ ActiveRecordMysqlXverify.handle_if = ->(config) do
49
57
  end
50
58
  # Default: ->(_) { true }
51
59
 
52
- ActiveRecordMysqlXverify.only_on_error = false
53
- # Default: true
54
-
55
60
  # CREATE DATABASE IF NOT EXISTS bookshelf;
56
61
  # CREATE TABLE bookshelf.books (id INT PRIMARY KEY);
57
62
  class Book < ActiveRecord::Base; end
@@ -74,7 +79,7 @@ In `config/environments/production.rb`:
74
79
 
75
80
  ```ruby
76
81
  ActiveRecordMysqlXverify.verify = ->(conn) do
77
- conn.ping && conn.query('show variables like "innodb_read_only"').first.fetch(1) == 'OFF'
82
+ conn.ping && conn.query('select @@innodb_read_only').first.fetch('@@innodb_read_only').zero?
78
83
  end
79
84
  # Same as below:
80
85
  # ActiveRecordMysqlXverify.verify = ActiveRecordMysqlXverify::Verifiers::AURORA_MASTER
@@ -131,8 +136,13 @@ Completed 302 Found in 150ms (ActiveRecord: 145.2ms)
131
136
 
132
137
  ## Test
133
138
 
139
+ ## Test
140
+
141
+ ```sh
142
+ docker-compose build
143
+ docker-compose run client bundle exec appraisal ar60 rake
134
144
  ```
135
- bundle install
136
- docker-compose up -d
137
- bundle exec rake
138
- ```
145
+
146
+ ## Related links
147
+
148
+ * https://github.com/winebarrel/active_record_postgresql_xverify
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'bundler/setup'
5
- require 'activerecord_mysql_xverify'
5
+ require 'active_record_mysql_xverify'
6
6
 
7
7
  # You can add fixtures and/or initialization code here to make experimenting
8
8
  # with your gem easier. You can also use a different console, if you like.
@@ -1,8 +1,12 @@
1
- version: '3'
1
+ version: "3.8"
2
2
  services:
3
+ client:
4
+ build: .
5
+ volumes:
6
+ - ./:/mnt
7
+ depends_on:
8
+ - mysql
3
9
  mysql:
4
10
  image: mysql:5.7
5
- ports:
6
- - 6033:3306
7
11
  environment:
8
- MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
12
+ MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.0.3"
6
+
7
+ gemspec path: "../"
@@ -4,7 +4,7 @@ module ActiveRecordMysqlXverify
4
4
  @config = {
5
5
  handle_if: ->(_) { true },
6
6
  verify: ->(conn) { conn.ping },
7
- only_on_error: true,
7
+ only_on_error: false,
8
8
  }
9
9
 
10
10
  class << self
@@ -3,7 +3,7 @@
3
3
  module ActiveRecordMysqlXverify
4
4
  module Verifiers
5
5
  AURORA_MASTER = lambda do |conn|
6
- conn.ping && conn.query('show variables like "innodb_read_only"').first.fetch(1) == 'OFF'
6
+ conn.ping && conn.query('select @@innodb_read_only').first.fetch('@@innodb_read_only').zero?
7
7
  end
8
8
  end
9
9
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordMysqlXverify
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.0'
5
5
  end
data/seq.wsd ADDED
@@ -0,0 +1,38 @@
1
+ @startuml{seq.png}
2
+
3
+ actor Client
4
+ participant Rails
5
+ participant "Connection pool" as cp
6
+ participant "<size:10>active_recode_mysql_xverify</size>" as armx
7
+ participant MySQL
8
+
9
+ Client -> Rails : Request
10
+ activate Rails
11
+ Rails -> MySQL : Query
12
+ activate MySQL
13
+ group neg
14
+ Rails <-- MySQL : <font color=red>"read-only" error happen!</font>
15
+ deactivate MySQL
16
+ Client <-- Rails : <font color=red>Error</font>
17
+ deactivate Rails
18
+ end
19
+
20
+ Client -> Rails : Request
21
+ activate Rails
22
+ Rails -> cp : checkout
23
+ activate cp
24
+ cp -> armx : active?
25
+ activate armx
26
+ armx -> MySQL : Fetch "innodb_read_only"
27
+ activate MySQL
28
+ armx <-- MySQL : "ON"
29
+ deactivate MySQL
30
+ cp <-- armx : false
31
+ deactivate armx
32
+ cp --> MySQL : reconnect!
33
+ activate MySQL
34
+ deactivate MySQL
35
+ Rails <-- cp : Connection
36
+ deactivate cp
37
+
38
+ @enduml
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_mysql_xverify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - winebarrel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-30 00:00:00.000000000 Z
11
+ date: 2020-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -121,6 +121,7 @@ files:
121
121
  - ".rubocop.yml"
122
122
  - ".travis.yml"
123
123
  - Appraisals
124
+ - Dockerfile
124
125
  - Gemfile
125
126
  - LICENSE.txt
126
127
  - README.md
@@ -134,6 +135,7 @@ files:
134
135
  - gemfiles/ar50.gemfile
135
136
  - gemfiles/ar51.gemfile
136
137
  - gemfiles/ar52.gemfile
138
+ - gemfiles/ar60.gemfile
137
139
  - lib/active_record_mysql_xverify.rb
138
140
  - lib/active_record_mysql_xverify/config.rb
139
141
  - lib/active_record_mysql_xverify/constants.rb
@@ -143,6 +145,7 @@ files:
143
145
  - lib/active_record_mysql_xverify/verifier.rb
144
146
  - lib/active_record_mysql_xverify/verifiers/aurora_master.rb
145
147
  - lib/active_record_mysql_xverify/version.rb
148
+ - seq.wsd
146
149
  homepage: https://github.com/winebarrel/active_record_mysql_xverify
147
150
  licenses:
148
151
  - MIT
@@ -162,8 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
165
  - !ruby/object:Gem::Version
163
166
  version: '0'
164
167
  requirements: []
165
- rubyforge_project:
166
- rubygems_version: 2.7.6.2
168
+ rubygems_version: 3.0.3
167
169
  signing_key:
168
170
  specification_version: 4
169
171
  summary: It is a library that performs extended verification when an error occurs