activerecord-tidb-adapter 0.5.0 → 5.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: 7e086031695fe37ee336da6d8722b947018501e8e3ce90051d00b83d7aebc742
4
- data.tar.gz: af2a51ca724563cc076f5bf0ef018eb0bd8bb15a756947c316e374f30b100396
3
+ metadata.gz: acd66282a9f0c498709a9258ca7337267c9cbd3770ce8a5d55d38be1607d4466
4
+ data.tar.gz: 8a73bc0cb0b685fa49e8247fd9d325e8800a95c6157b12c8eaa089bc85d47277
5
5
  SHA512:
6
- metadata.gz: f8e0c432e30009832966b1a70d3a2842e9b64c9fa417c3744952c0d1feb6d64a956308496dcab19ba36ac2c9da7e48a0fa94d69ad14fa4a5d2849781b6fa8bcd
7
- data.tar.gz: 844d1511bb454844e4d179b7c519dbcac9398a9e4df6ad3df85f8396d1f7b687ef3f13a77330f1126c4b6479fb8fe1f472c5feae8b3002f386e964626d005120
6
+ metadata.gz: 9a478110b32ee9acaeaa7570a207f5721fa91cce9547f1c83bc89ab52e7b59f8401b3ccde38b4c224e8918d16fc2d1e376dca52a0bac316c77be8011161169a8
7
+ data.tar.gz: d9a0cdc919c9e09df981b779aa5b60b63fa927fcb93420d8629c671d96562b3f45c8a6280187813caefb5f3b39dd980d66584fbddc6d35bc7d80c11b7e96722d
data/Gemfile CHANGED
@@ -14,10 +14,14 @@ gem 'pry'
14
14
 
15
15
  gem 'rubocop', '~> 1.18'
16
16
 
17
- gem 'rails', git: 'https://github.com/tidb-incubator/rails.git', branch: '6-1-stable'
17
+ gem 'rails', git: 'https://github.com/pingcap/rails.git', branch: '5-2-stable'
18
18
 
19
19
  gem 'byebug', '~> 11.1'
20
20
 
21
21
  gem 'sqlite3', '~> 1.4'
22
22
 
23
23
  gem 'pg', '~> 1.2'
24
+
25
+ gem "mocha", "~> 1.13"
26
+
27
+ gem "bcrypt", "~> 3.1"
data/Gemfile.lock CHANGED
@@ -1,100 +1,82 @@
1
1
  GIT
2
- remote: https://github.com/tidb-incubator/rails.git
3
- revision: e2a3d3fb2ee24c709b9f32221fbcb66cfda5acfc
4
- branch: 6-1-stable
2
+ remote: https://github.com/pingcap/rails.git
3
+ revision: 7a3fbc5e103be80107fabc9e626cfc32e10e6e1c
4
+ branch: 5-2-stable
5
5
  specs:
6
- actioncable (6.1.4)
7
- actionpack (= 6.1.4)
8
- activesupport (= 6.1.4)
6
+ actioncable (5.2.6)
7
+ actionpack (= 5.2.6)
9
8
  nio4r (~> 2.0)
10
9
  websocket-driver (>= 0.6.1)
11
- actionmailbox (6.1.4)
12
- actionpack (= 6.1.4)
13
- activejob (= 6.1.4)
14
- activerecord (= 6.1.4)
15
- activestorage (= 6.1.4)
16
- activesupport (= 6.1.4)
17
- mail (>= 2.7.1)
18
- actionmailer (6.1.4)
19
- actionpack (= 6.1.4)
20
- actionview (= 6.1.4)
21
- activejob (= 6.1.4)
22
- activesupport (= 6.1.4)
10
+ actionmailer (5.2.6)
11
+ actionpack (= 5.2.6)
12
+ actionview (= 5.2.6)
13
+ activejob (= 5.2.6)
23
14
  mail (~> 2.5, >= 2.5.4)
24
15
  rails-dom-testing (~> 2.0)
25
- actionpack (6.1.4)
26
- actionview (= 6.1.4)
27
- activesupport (= 6.1.4)
28
- rack (~> 2.0, >= 2.0.9)
16
+ actionpack (5.2.6)
17
+ actionview (= 5.2.6)
18
+ activesupport (= 5.2.6)
19
+ rack (~> 2.0, >= 2.0.8)
29
20
  rack-test (>= 0.6.3)
30
21
  rails-dom-testing (~> 2.0)
31
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
32
- actiontext (6.1.4)
33
- actionpack (= 6.1.4)
34
- activerecord (= 6.1.4)
35
- activestorage (= 6.1.4)
36
- activesupport (= 6.1.4)
37
- nokogiri (>= 1.8.5)
38
- actionview (6.1.4)
39
- activesupport (= 6.1.4)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
23
+ actionview (5.2.6)
24
+ activesupport (= 5.2.6)
40
25
  builder (~> 3.1)
41
26
  erubi (~> 1.4)
42
27
  rails-dom-testing (~> 2.0)
43
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
44
- activejob (6.1.4)
45
- activesupport (= 6.1.4)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
29
+ activejob (5.2.6)
30
+ activesupport (= 5.2.6)
46
31
  globalid (>= 0.3.6)
47
- activemodel (6.1.4)
48
- activesupport (= 6.1.4)
49
- activerecord (6.1.4)
50
- activemodel (= 6.1.4)
51
- activesupport (= 6.1.4)
52
- activestorage (6.1.4)
53
- actionpack (= 6.1.4)
54
- activejob (= 6.1.4)
55
- activerecord (= 6.1.4)
56
- activesupport (= 6.1.4)
32
+ activemodel (5.2.6)
33
+ activesupport (= 5.2.6)
34
+ activerecord (5.2.6)
35
+ activemodel (= 5.2.6)
36
+ activesupport (= 5.2.6)
37
+ arel (>= 9.0)
38
+ activestorage (5.2.6)
39
+ actionpack (= 5.2.6)
40
+ activerecord (= 5.2.6)
57
41
  marcel (~> 1.0.0)
58
- mini_mime (>= 1.1.0)
59
- activesupport (6.1.4)
42
+ activesupport (5.2.6)
60
43
  concurrent-ruby (~> 1.0, >= 1.0.2)
61
- i18n (>= 1.6, < 2)
62
- minitest (>= 5.1)
63
- tzinfo (~> 2.0)
64
- zeitwerk (~> 2.3)
65
- rails (6.1.4)
66
- actioncable (= 6.1.4)
67
- actionmailbox (= 6.1.4)
68
- actionmailer (= 6.1.4)
69
- actionpack (= 6.1.4)
70
- actiontext (= 6.1.4)
71
- actionview (= 6.1.4)
72
- activejob (= 6.1.4)
73
- activemodel (= 6.1.4)
74
- activerecord (= 6.1.4)
75
- activestorage (= 6.1.4)
76
- activesupport (= 6.1.4)
77
- bundler (>= 1.15.0)
78
- railties (= 6.1.4)
44
+ i18n (>= 0.7, < 2)
45
+ minitest (~> 5.1)
46
+ tzinfo (~> 1.1)
47
+ rails (5.2.6)
48
+ actioncable (= 5.2.6)
49
+ actionmailer (= 5.2.6)
50
+ actionpack (= 5.2.6)
51
+ actionview (= 5.2.6)
52
+ activejob (= 5.2.6)
53
+ activemodel (= 5.2.6)
54
+ activerecord (= 5.2.6)
55
+ activestorage (= 5.2.6)
56
+ activesupport (= 5.2.6)
57
+ bundler (>= 1.3.0)
58
+ railties (= 5.2.6)
79
59
  sprockets-rails (>= 2.0.0)
80
- railties (6.1.4)
81
- actionpack (= 6.1.4)
82
- activesupport (= 6.1.4)
60
+ railties (5.2.6)
61
+ actionpack (= 5.2.6)
62
+ activesupport (= 5.2.6)
83
63
  method_source
84
- rake (>= 0.13)
85
- thor (~> 1.0)
64
+ rake (>= 0.8.7)
65
+ thor (>= 0.19.0, < 2.0)
86
66
 
87
67
  PATH
88
68
  remote: .
89
69
  specs:
90
- activerecord-tidb-adapter (0.5.0)
91
- activerecord (~> 6.1)
70
+ activerecord-tidb-adapter (5.2.0)
71
+ activerecord (~> 5.2)
92
72
  mysql2
93
73
 
94
74
  GEM
95
75
  remote: https://rubygems.org/
96
76
  specs:
77
+ arel (9.0.0)
97
78
  ast (2.4.2)
79
+ bcrypt (3.1.16)
98
80
  builder (3.2.4)
99
81
  byebug (11.1.3)
100
82
  coderay (1.1.3)
@@ -116,6 +98,7 @@ GEM
116
98
  minitest (5.14.4)
117
99
  minitest-excludes (2.0.1)
118
100
  minitest (~> 5.0)
101
+ mocha (1.13.0)
119
102
  mysql2 (0.5.3)
120
103
  nio4r (2.5.8)
121
104
  nokogiri (1.12.3-x86_64-darwin)
@@ -136,7 +119,7 @@ GEM
136
119
  rails-dom-testing (2.0.3)
137
120
  activesupport (>= 4.2.0)
138
121
  nokogiri (>= 1.6)
139
- rails-html-sanitizer (1.3.0)
122
+ rails-html-sanitizer (1.4.1)
140
123
  loofah (~> 2.3)
141
124
  rainbow (3.0.0)
142
125
  rake (13.0.6)
@@ -163,13 +146,13 @@ GEM
163
146
  sprockets (>= 3.0.0)
164
147
  sqlite3 (1.4.2)
165
148
  thor (1.1.0)
166
- tzinfo (2.0.4)
167
- concurrent-ruby (~> 1.0)
149
+ thread_safe (0.3.6)
150
+ tzinfo (1.2.9)
151
+ thread_safe (~> 0.1)
168
152
  unicode-display_width (2.0.0)
169
153
  websocket-driver (0.7.5)
170
154
  websocket-extensions (>= 0.1.0)
171
155
  websocket-extensions (0.1.5)
172
- zeitwerk (2.4.2)
173
156
 
174
157
  PLATFORMS
175
158
  x86_64-darwin-18
@@ -177,9 +160,11 @@ PLATFORMS
177
160
 
178
161
  DEPENDENCIES
179
162
  activerecord-tidb-adapter!
163
+ bcrypt (~> 3.1)
180
164
  byebug (~> 11.1)
181
165
  minitest (~> 5.0)
182
166
  minitest-excludes (~> 2.0)
167
+ mocha (~> 1.13)
183
168
  pg (~> 1.2)
184
169
  pry
185
170
  rails!
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ['lib']
31
31
 
32
- spec.add_dependency 'activerecord', '~> 6.1'
32
+ spec.add_dependency 'activerecord', '~> 5.2'
33
33
  spec.add_dependency 'mysql2'
34
34
 
35
35
  # Uncomment to register a new dependency of your gem
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_record/connection_adapters'
4
3
  require 'active_record/connection_adapters/mysql2_adapter'
5
4
  require 'active_record/connection_adapters/tidb/setup'
6
5
  require_relative '../../version'
@@ -30,7 +29,28 @@ module ActiveRecord
30
29
  end
31
30
  end
32
31
 
32
+
33
+
33
34
  module ConnectionAdapters
35
+ class Mysql2Adapter < AbstractMysqlAdapter
36
+ ER_BAD_DB_ERROR = 1049
37
+ ADAPTER_NAME = "Mysql2"
38
+
39
+ include MySQL::DatabaseStatements
40
+
41
+ class << self
42
+ def new_client(config)
43
+ Mysql2::Client.new(config)
44
+ rescue Mysql2::Error => error
45
+ if error.error_number == ConnectionAdapters::Mysql2Adapter::ER_BAD_DB_ERROR
46
+ raise ActiveRecord::NoDatabaseError
47
+ else
48
+ raise ActiveRecord::ConnectionNotEstablished, error.message
49
+ end
50
+ end
51
+ end
52
+ end
53
+
34
54
  class TidbAdapter < Mysql2Adapter
35
55
  include ActiveRecord::Sequence::Adapter
36
56
  ADAPTER_NAME = 'Tidb'
@@ -105,42 +125,35 @@ module ActiveRecord
105
125
  value = exec_insert(sql, name, binds, pk, sequence_name)
106
126
  return id_value if id_value.present?
107
127
 
108
- model = arel.ast.relation.instance_variable_get(:@klass)
109
- pk_def = schema_cache.columns_hash(model.table_name)[pk]
128
+ table_name = arel.ast.relation.table_name
129
+ pk_def = schema_cache.columns_hash(table_name)[pk]
110
130
  if pk_def&.default_function && pk_def.default_function =~ /nextval/
111
131
  query_value("SELECT #{pk_def.default_function.sub('nextval', 'lastval')}")
112
- elsif model.sequence_name
113
- ActiveRecord::Base.lastval(model.sequence_name)
114
132
  else
115
133
  last_inserted_id(value)
116
134
  end
117
135
  end
118
136
  alias create insert
119
137
 
120
- def new_column_from_field(_table_name, field)
138
+ def new_column_from_field(table_name, field)
121
139
  type_metadata = fetch_type_metadata(field[:Type], field[:Extra])
122
- default = field[:Default]
123
- default_function = nil
124
-
125
- if type_metadata.type == :datetime && /\ACURRENT_TIMESTAMP(?:\([0-6]?\))?\z/i.match?(default)
126
- default_function = default
127
- default = nil
128
- elsif type_metadata.extra == 'DEFAULT_GENERATED'
129
- default = +"(#{default})" unless default.start_with?('(')
130
- default_function = default
131
- default = nil
140
+ if type_metadata.type == :datetime && /\ACURRENT_TIMESTAMP(?:\([0-6]?\))?\z/i.match?(field[:Default])
141
+ default, default_function = nil, field[:Default]
132
142
  elsif default.to_s =~ /nextval/i
133
143
  default_function = default
134
144
  default = nil
145
+ else
146
+ default, default_function = field[:Default], nil
135
147
  end
136
148
 
137
149
  MySQL::Column.new(
138
150
  field[:Field],
139
151
  default,
140
152
  type_metadata,
141
- field[:Null] == 'YES',
153
+ field[:Null] == "YES",
154
+ table_name,
142
155
  default_function,
143
- collation: field[:Collation],
156
+ field[:Collation],
144
157
  comment: field[:Comment].presence
145
158
  )
146
159
  end
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecord
4
- TIDB_ADAPTER_VERSION = '0.5.0'
4
+ TIDB_ADAPTER_VERSION = '5.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-tidb-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hooopo Wang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-17 00:00:00.000000000 Z
11
+ date: 2021-08-19 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: '6.1'
19
+ version: '5.2'
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: '6.1'
26
+ version: '5.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mysql2
29
29
  requirement: !ruby/object:Gem::Requirement