activerecord-pedantmysql2-adapter 1.1.3 → 1.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fb193accc432a0fed85a527c520afef1f5bf3c43
4
- data.tar.gz: b11fe06882e5086459d26f52cd59bcfb6ead0327
2
+ SHA256:
3
+ metadata.gz: '0191edcf1291b66b644b0ee2aae2c192559dda880347270f4bac423ff0dae468'
4
+ data.tar.gz: ddbb36a60520e44f314416fbfac0bbef65cd89c7f2b6f7ecd0c13468c6a9d9d9
5
5
  SHA512:
6
- metadata.gz: e8146d26e36fa99f37a3c08277da4db95210a3fabc0ad6764dde8de9cefa3751ac1a4f79ee97733cc058ab704878100459c7dc3f5c95b612c803c5a16b5f1fd8
7
- data.tar.gz: f950e21b77652402beb3ebd2e7d5786f59f47d97a1568120d7fe19e6b9a84abccdb0fb9f4c53ff0c3eae82f2b4222ebf6a2fab5198128bd69343824c15150027
6
+ metadata.gz: 70a10d0462324fddae3d76bc4e74fb0f62b7db8f4a65c3153ce7b5ce03b897ce7587ea402122a5b2226abf6412c9aa4367c2316f82bb1c7589548a582de24cbd
7
+ data.tar.gz: 90050a09ffec4d32945213f19360a11f3b993ef858806f465d57822d4dadb5d57281d84d60b46fac2a16a16b29b0d11bf77d344bbd213124b00c910e697fae48
@@ -0,0 +1,28 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ name: Ruby ${{ matrix.ruby }} / Active Record ${{ matrix.activerecord }}
9
+ strategy:
10
+ matrix:
11
+ ruby: ['2.7', '3.0', '3.1']
12
+ activerecord: ['6.1', '7.0', 'edge']
13
+ env:
14
+ BUNDLE_GEMFILE: gemfiles/Gemfile.activerecord-${{ matrix.activerecord }}
15
+ steps:
16
+ - name: Check out code
17
+ uses: actions/checkout@v2
18
+ - name: Set up Ruby ${{ matrix.ruby }}
19
+ uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby }}
22
+ bundler-cache: true
23
+ - name: Start MySQL and create DB
24
+ run: |
25
+ sudo systemctl start mysql.service
26
+ mysql -uroot -proot -e 'create database pedant_mysql2_test;'
27
+ - name: Ruby Tests
28
+ run: bundle exec rake
data/README.md CHANGED
@@ -52,7 +52,7 @@ and to restore it to raising warnings as errors:
52
52
  PedantMysql2.raise_warnings!
53
53
  ```
54
54
 
55
- You can easilly whitelist some types of warnings:
55
+ You can easily whitelist some types of warnings:
56
56
 
57
57
  ```ruby
58
58
  PedantMysql2.ignore(/Some warning I don't care about/i)
@@ -13,16 +13,20 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = 'https://github.com/Shopify/activerecord-pedantmysql2-adapter'
14
14
  spec.license = 'MIT'
15
15
 
16
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
17
+
18
+ spec.required_ruby_version = '>= 2.2.2'
19
+
16
20
  spec.files = `git ls-files -z`.split("\x0")
17
21
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
22
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
23
  spec.require_paths = ['lib']
20
24
 
21
- spec.add_dependency 'activerecord', '>= 3.2'
25
+ spec.add_dependency 'activerecord', '>= 6.0'
22
26
  spec.add_dependency 'mysql2', '>= 0.3.12'
23
- spec.add_development_dependency 'bundler', '~> 1.5'
27
+
28
+ spec.add_development_dependency 'bundler'
24
29
  spec.add_development_dependency 'rake'
25
30
  spec.add_development_dependency 'rspec', '>= 3.0'
26
31
  spec.add_development_dependency 'rspec-its'
27
- spec.add_development_dependency 'coveralls'
28
32
  end
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+ gemspec path: '..'
3
+
4
+ gem 'activerecord', '~> 6.0.1'
5
+ gem 'mysql2'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+ gemspec path: '..'
3
+
4
+ gem 'activerecord', '~> 7.0.0'
5
+ gem 'mysql2'
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec path: '..'
3
+
4
+ gem 'activerecord', github: 'rails/rails', branch: 'main'
@@ -2,24 +2,44 @@ require 'active_record/connection_adapters/mysql2_adapter'
2
2
 
3
3
  module ActiveRecord
4
4
  module ConnectionHandling
5
- def pedant_mysql2_connection(config)
6
- config = config.symbolize_keys
7
-
8
- config[:username] = 'root' if config[:username].nil?
9
-
10
- if Mysql2::Client.const_defined? :FOUND_ROWS
11
- config[:flags] = Mysql2::Client::FOUND_ROWS
5
+ if ConnectionAdapters::Mysql2Adapter.respond_to?(:new_client)
6
+ def pedant_mysql2_connection(config)
7
+ config = config.symbolize_keys
8
+ config[:flags] ||= 0
9
+
10
+ if config[:flags].kind_of? Array
11
+ config[:flags].push "FOUND_ROWS"
12
+ else
13
+ config[:flags] |= Mysql2::Client::FOUND_ROWS
14
+ end
15
+
16
+ ConnectionAdapters::PedantMysql2Adapter.new(
17
+ ConnectionAdapters::Mysql2Adapter.new_client(config),
18
+ logger,
19
+ nil,
20
+ config,
21
+ )
12
22
  end
13
-
14
- client = Mysql2::Client.new(config)
15
-
16
- options = [config[:host], config[:username], config[:password], config[:database], config[:port], config[:socket], 0]
17
- ActiveRecord::ConnectionAdapters::PedantMysql2Adapter.new(client, logger, options, config)
18
- rescue Mysql2::Error => error
19
- if error.message.include?("Unknown database") && defined?(ActiveRecord::NoDatabaseError)
20
- raise ActiveRecord::NoDatabaseError.new(error.message)
21
- else
22
- raise
23
+ else
24
+ def pedant_mysql2_connection(config)
25
+ config = config.symbolize_keys
26
+
27
+ config[:username] = 'root' if config[:username].nil?
28
+
29
+ if Mysql2::Client.const_defined? :FOUND_ROWS
30
+ config[:flags] = Mysql2::Client::FOUND_ROWS
31
+ end
32
+
33
+ client = Mysql2::Client.new(config)
34
+
35
+ options = [config[:host], config[:username], config[:password], config[:database], config[:port], config[:socket], 0]
36
+ ActiveRecord::ConnectionAdapters::PedantMysql2Adapter.new(client, logger, options, config)
37
+ rescue Mysql2::Error => error
38
+ if error.message.include?("Unknown database") && defined?(ActiveRecord::NoDatabaseError)
39
+ raise ActiveRecord::NoDatabaseError.new(error.message)
40
+ else
41
+ raise
42
+ end
23
43
  end
24
44
  end
25
45
  end
@@ -38,11 +58,12 @@ class MysqlWarning < StandardError
38
58
  end
39
59
 
40
60
  class ActiveRecord::ConnectionAdapters::PedantMysql2Adapter < ActiveRecord::ConnectionAdapters::Mysql2Adapter
41
- def execute(sql, name = nil)
61
+ def execute(sql, *)
42
62
  value = super
43
63
  log_warnings(sql)
44
64
  value
45
65
  end
66
+ ruby2_keywords :execute if respond_to?(:ruby2_keywords, true)
46
67
 
47
68
  def exec_delete(sql, name, binds)
48
69
  @affected_rows_before_logging = nil
@@ -55,10 +76,13 @@ class ActiveRecord::ConnectionAdapters::PedantMysql2Adapter < ActiveRecord::Conn
55
76
  private
56
77
 
57
78
  def log_warnings(sql)
58
- return unless @connection.warning_count > 0
79
+ # support for https://github.com/rails/rails/commit/d86fd6415c0dfce6fadb77e74696cf728e5eb76b
80
+ connection = instance_variable_defined?(:@raw_connection) ? @raw_connection : @connection
81
+
82
+ return unless connection.warning_count > 0
59
83
 
60
- @affected_rows_before_logging = @connection.affected_rows
61
- result = @connection.query('SHOW WARNINGS')
84
+ @affected_rows_before_logging = connection.affected_rows
85
+ result = connection.query('SHOW WARNINGS')
62
86
 
63
87
  result.each do |level, code, message|
64
88
  warning = MysqlWarning.new(message, code, level, sql)
@@ -1,3 +1,3 @@
1
1
  module PedantMysql2
2
- VERSION = '1.1.3'
2
+ VERSION = '1.3.1'
3
3
  end
data/lib/pedant_mysql2.rb CHANGED
@@ -46,11 +46,11 @@ module PedantMysql2
46
46
  end
47
47
 
48
48
  def ignored?(warning)
49
- whitelist.any? { |matcher| matcher =~ warning.message } || drop_table_warning(warning)
49
+ whitelist.any? { |matcher| warning.message.match?(matcher) } || drop_table_warning(warning)
50
50
  end
51
51
 
52
52
  def drop_table_warning(warning)
53
- warning.query =~ /\ADROP TABLE IF EXISTS/ || warning.message =~ /\AUnknown table/
53
+ warning.query.match?(/\ADROP TABLE IF EXISTS/) || warning.message.match?(/\AUnknown table/)
54
54
  end
55
55
 
56
56
  def setup_capture
data/spec/adapter_spec.rb CHANGED
@@ -7,7 +7,7 @@ describe PedantMysql2 do
7
7
  before :each do
8
8
  PedantMysql2.raise_warnings!
9
9
  PedantMysql2.instance_variable_set(:@whitelist, nil)
10
- connection.execute('SET SESSION binlog_format = "STATEMENT"')
10
+ PedantMysql2.ignore(/They will be merged with strict mode in a future release/)
11
11
  if connection.execute('SHOW TABLES LIKE "comment"').size == 0
12
12
  connection.execute('CREATE TABLE comment (id int)')
13
13
  end
@@ -12,7 +12,12 @@ describe ActiveRecord::ConnectionHandling do
12
12
  it 'raises NoDatabaseError correctly' do
13
13
  error_class = defined?(ActiveRecord::NoDatabaseError) ? ActiveRecord::NoDatabaseError : Mysql2::Error
14
14
  expect {
15
- Mock.new.pedant_mysql2_connection({host: 'localhost', database: 'nosuchthing'})
15
+ Mock.new.pedant_mysql2_connection({
16
+ host: TestSupport::DB_CONFIG['hostname'],
17
+ username: TestSupport::DB_CONFIG['username'],
18
+ password: TestSupport::DB_CONFIG['password'],
19
+ database: 'nosuchthing',
20
+ })
16
21
  }.to raise_error(error_class)
17
22
  end
18
23
 
data/spec/spec_helper.rb CHANGED
@@ -2,16 +2,23 @@ lib = File.expand_path('../lib', __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  require 'rspec/its'
5
- require 'simplecov'
6
- require 'coveralls'
7
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
- SimpleCov::Formatter::HTMLFormatter,
9
- Coveralls::SimpleCov::Formatter
10
- ]
11
- SimpleCov.start
12
-
13
5
  require 'activerecord-pedantmysql2-adapter'
14
6
 
7
+ module TestSupport
8
+ DB_CONFIG = {
9
+ 'adapter' => 'pedant_mysql2',
10
+ 'database' => 'pedant_mysql2_test',
11
+ 'username' => 'root',
12
+ 'password' => ENV['CI'] ? 'root' : nil,
13
+ 'encoding' => 'utf8mb4',
14
+ 'host' => 'localhost',
15
+ 'strict' => false,
16
+ 'pool' => 5,
17
+ }.freeze
18
+ end
19
+
20
+ ActiveRecord::Base.establish_connection(TestSupport::DB_CONFIG)
21
+
15
22
  Dir[File.expand_path(File.join(File.dirname(__FILE__), 'support', '**', '*.rb'))].each { |f| require f }
16
23
 
17
24
  RSpec.configure do |config|
@@ -1,11 +0,0 @@
1
- ActiveRecord::Base.configurations = {
2
- 'test' => {
3
- adapter: 'pedant_mysql2',
4
- database: 'pedant_mysql2_test',
5
- username: 'travis',
6
- encoding: 'utf8',
7
- strict: false,
8
- pool: 5,
9
- },
10
- }
11
- ActiveRecord::Base.establish_connection(:test)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-pedantmysql2-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-27 00:00:00.000000000 Z
11
+ date: 2022-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.2'
19
+ version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.2'
26
+ version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mysql2
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.5'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '1.5'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -94,20 +94,6 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: coveralls
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
97
  description: Gives a hook on MySQL warnings that allow you to either raise or log
112
98
  them.
113
99
  email:
@@ -116,24 +102,21 @@ executables: []
116
102
  extensions: []
117
103
  extra_rdoc_files: []
118
104
  files:
105
+ - ".github/workflows/ci.yml"
119
106
  - ".gitignore"
120
107
  - ".rspec"
121
- - ".travis.yml"
122
108
  - Gemfile
123
- - Gemfile.activerecord32
124
- - Gemfile.activerecord40
125
- - Gemfile.activerecord41
126
- - Gemfile.activerecord42
127
- - Gemfile.activerecord50
128
109
  - LICENSE.txt
129
110
  - README.md
130
111
  - Rakefile
131
112
  - activerecord-pedantmysql2-adapter.gemspec
113
+ - gemfiles/Gemfile.activerecord-6.1
114
+ - gemfiles/Gemfile.activerecord-7.0
115
+ - gemfiles/Gemfile.activerecord-edge
132
116
  - lib/active_record/connection_adapters/pedant_mysql2_adapter.rb
133
117
  - lib/activerecord-pedantmysql2-adapter.rb
134
118
  - lib/pedant_mysql2.rb
135
119
  - lib/pedant_mysql2/version.rb
136
- - shipit.rubygems.yml
137
120
  - spec/adapter_spec.rb
138
121
  - spec/connection_spec.rb
139
122
  - spec/spec_helper.rb
@@ -141,7 +124,8 @@ files:
141
124
  homepage: https://github.com/Shopify/activerecord-pedantmysql2-adapter
142
125
  licenses:
143
126
  - MIT
144
- metadata: {}
127
+ metadata:
128
+ allowed_push_host: https://rubygems.org
145
129
  post_install_message:
146
130
  rdoc_options: []
147
131
  require_paths:
@@ -150,15 +134,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
150
134
  requirements:
151
135
  - - ">="
152
136
  - !ruby/object:Gem::Version
153
- version: '0'
137
+ version: 2.2.2
154
138
  required_rubygems_version: !ruby/object:Gem::Requirement
155
139
  requirements:
156
140
  - - ">="
157
141
  - !ruby/object:Gem::Version
158
142
  version: '0'
159
143
  requirements: []
160
- rubyforge_project:
161
- rubygems_version: 2.5.2
144
+ rubygems_version: 3.2.20
162
145
  signing_key:
163
146
  specification_version: 4
164
147
  summary: ActiveRecord adapter for MySQL that report warnings.
data/.travis.yml DELETED
@@ -1,27 +0,0 @@
1
- rvm:
2
- - 1.9.3
3
- - 2.0.0
4
- - 2.1.2
5
- - 2.2.2
6
- - 2.3.0
7
-
8
- gemfile:
9
- - Gemfile.activerecord32
10
- - Gemfile.activerecord40
11
- - Gemfile.activerecord41
12
- - Gemfile.activerecord42
13
- - Gemfile.activerecord50
14
-
15
- matrix:
16
- exclude:
17
- - rvm: 1.9.3
18
- gemfile: Gemfile.activerecord50
19
- - rvm: 2.0.0
20
- gemfile: Gemfile.activerecord50
21
- - rvm: 2.1.2
22
- gemfile: Gemfile.activerecord50
23
-
24
- before_script:
25
- - mysql -e 'create database pedant_mysql2_test;'
26
-
27
- sudo: false
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
- gemspec
3
-
4
- gem 'activerecord', '~> 3.2.0'
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
- gemspec
3
-
4
- gem 'activerecord', '~> 4.0.0'
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
- gemspec
3
-
4
- gem 'activerecord', '~> 4.1.0'
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
- gemspec
3
-
4
- gem 'activerecord', '~> 4.2.0.rc1'
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
- gemspec
3
-
4
- gem 'activerecord', '~> 5.0.0'
data/shipit.rubygems.yml DELETED
@@ -1,2 +0,0 @@
1
- fetch:
2
- - fetch-gem-version activerecord-pedantmysql2-adapter Shopify/activerecord-pedantmysql2-adapter