activerecord-tidb-adapter 5.2.2 → 6.1.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: 1ec81c5f43cb98b0fe8fb61484ea7b0050a84cb8c7caac6d25e314d58f5f1be0
4
- data.tar.gz: 4a99eafd9d2f53885e063cc89af6ecf2afce3506e0f9b118a999e52c5fe93e71
3
+ metadata.gz: 5f82e1eb06fb93971e146fafade1c45e2e3c5909e3968f32a719c9581efb55f3
4
+ data.tar.gz: 5a0bc0100489a41230115924cbff3f52e1ef2206441724116135ed01ccdd28da
5
5
  SHA512:
6
- metadata.gz: 66909adaf233af63fb1f7f251cb8f11ba4a484c80e7646c9202c5636a7477575880f85927e01403ce26f8ebaa4a88c5eea6ffa1052a5a34d4e8b12d18f5cbb86
7
- data.tar.gz: 8ad7289243de4d4f4e1b34d759be041f33c5b02d6b99428e9fc09ad918baa021751d708adc335c126495dce29eae9fca61a63cf7533711c7cd88cb6caf3511a3
6
+ metadata.gz: 0b059eabd253b3e7e0ead32528ac380d874dd9ab42ff942ec86ff3ddec86257b00aa5aea3c44912f95d3c0c8ba2dc7e8ba0a33abff668f6100f929fc2ed45f61
7
+ data.tar.gz: 216b0b9917670ca40cd30d3c243493e88aaf2279d946b68eaa927b0a65d78226e075279f12c8839f32a4d9be8b3edb7c348ba2038cd25bfa2845dc62aa9d4944
data/Gemfile CHANGED
@@ -14,14 +14,10 @@ gem 'pry'
14
14
 
15
15
  gem 'rubocop', '~> 1.18'
16
16
 
17
- gem 'rails', git: 'https://github.com/pingcap/rails.git', branch: '5-2-stable'
17
+ gem 'rails', git: 'https://github.com/pingcap/rails.git', branch: '6-1-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,82 +1,100 @@
1
1
  GIT
2
2
  remote: https://github.com/pingcap/rails.git
3
- revision: a1adbde17b229e9131d40787ee4342c1180afb36
4
- branch: 5-2-stable
3
+ revision: e2a3d3fb2ee24c709b9f32221fbcb66cfda5acfc
4
+ branch: 6-1-stable
5
5
  specs:
6
- actioncable (5.2.6)
7
- actionpack (= 5.2.6)
6
+ actioncable (6.1.4)
7
+ actionpack (= 6.1.4)
8
+ activesupport (= 6.1.4)
8
9
  nio4r (~> 2.0)
9
10
  websocket-driver (>= 0.6.1)
10
- actionmailer (5.2.6)
11
- actionpack (= 5.2.6)
12
- actionview (= 5.2.6)
13
- activejob (= 5.2.6)
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)
14
23
  mail (~> 2.5, >= 2.5.4)
15
24
  rails-dom-testing (~> 2.0)
16
- actionpack (5.2.6)
17
- actionview (= 5.2.6)
18
- activesupport (= 5.2.6)
19
- rack (~> 2.0, >= 2.0.8)
25
+ actionpack (6.1.4)
26
+ actionview (= 6.1.4)
27
+ activesupport (= 6.1.4)
28
+ rack (~> 2.0, >= 2.0.9)
20
29
  rack-test (>= 0.6.3)
21
30
  rails-dom-testing (~> 2.0)
22
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
23
- actionview (5.2.6)
24
- activesupport (= 5.2.6)
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)
25
40
  builder (~> 3.1)
26
41
  erubi (~> 1.4)
27
42
  rails-dom-testing (~> 2.0)
28
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
29
- activejob (5.2.6)
30
- activesupport (= 5.2.6)
43
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
44
+ activejob (6.1.4)
45
+ activesupport (= 6.1.4)
31
46
  globalid (>= 0.3.6)
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)
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)
41
57
  marcel (~> 1.0.0)
42
- activesupport (5.2.6)
58
+ mini_mime (>= 1.1.0)
59
+ activesupport (6.1.4)
43
60
  concurrent-ruby (~> 1.0, >= 1.0.2)
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)
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)
59
79
  sprockets-rails (>= 2.0.0)
60
- railties (5.2.6)
61
- actionpack (= 5.2.6)
62
- activesupport (= 5.2.6)
80
+ railties (6.1.4)
81
+ actionpack (= 6.1.4)
82
+ activesupport (= 6.1.4)
63
83
  method_source
64
- rake (>= 0.8.7)
65
- thor (>= 0.19.0, < 2.0)
84
+ rake (>= 0.13)
85
+ thor (~> 1.0)
66
86
 
67
87
  PATH
68
88
  remote: .
69
89
  specs:
70
- activerecord-tidb-adapter (5.2.2)
71
- activerecord (~> 5.2)
90
+ activerecord-tidb-adapter (6.1.0)
91
+ activerecord (~> 6.1)
72
92
  mysql2
73
93
 
74
94
  GEM
75
95
  remote: https://rubygems.org/
76
96
  specs:
77
- arel (9.0.0)
78
97
  ast (2.4.2)
79
- bcrypt (3.1.16)
80
98
  builder (3.2.4)
81
99
  byebug (11.1.3)
82
100
  coderay (1.1.3)
@@ -98,7 +116,6 @@ GEM
98
116
  minitest (5.14.4)
99
117
  minitest-excludes (2.0.1)
100
118
  minitest (~> 5.0)
101
- mocha (1.13.0)
102
119
  mysql2 (0.5.3)
103
120
  nio4r (2.5.8)
104
121
  nokogiri (1.12.3-x86_64-darwin)
@@ -146,13 +163,13 @@ GEM
146
163
  sprockets (>= 3.0.0)
147
164
  sqlite3 (1.4.2)
148
165
  thor (1.1.0)
149
- thread_safe (0.3.6)
150
- tzinfo (1.2.9)
151
- thread_safe (~> 0.1)
166
+ tzinfo (2.0.4)
167
+ concurrent-ruby (~> 1.0)
152
168
  unicode-display_width (2.0.0)
153
169
  websocket-driver (0.7.5)
154
170
  websocket-extensions (>= 0.1.0)
155
171
  websocket-extensions (0.1.5)
172
+ zeitwerk (2.4.2)
156
173
 
157
174
  PLATFORMS
158
175
  x86_64-darwin-18
@@ -160,11 +177,9 @@ PLATFORMS
160
177
 
161
178
  DEPENDENCIES
162
179
  activerecord-tidb-adapter!
163
- bcrypt (~> 3.1)
164
180
  byebug (~> 11.1)
165
181
  minitest (~> 5.0)
166
182
  minitest-excludes (~> 2.0)
167
- mocha (~> 1.13)
168
183
  pg (~> 1.2)
169
184
  pry
170
185
  rails!
data/README.md CHANGED
@@ -8,7 +8,7 @@ TiDB adapter for ActiveRecord 5 and 6. This is a lightweight extension of the my
8
8
  Add this line to your application's Gemfile:
9
9
 
10
10
  ```ruby
11
- gem 'activerecord-tidb-adapter', "~> 5.2.2"
11
+ gem 'activerecord-tidb-adapter', "~> 6.1.0"
12
12
  ```
13
13
 
14
14
  And then execute:
@@ -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', '~> 5.2'
32
+ spec.add_dependency 'activerecord', '~> 6.1'
33
33
  spec.add_dependency 'mysql2'
34
34
 
35
35
  # Uncomment to register a new dependency of your gem
@@ -1,11 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_record/connection_adapters'
3
4
  require 'active_record/connection_adapters/mysql2_adapter'
4
5
  require 'active_record/connection_adapters/tidb/setup'
5
6
  require_relative '../../version'
6
7
  require_relative '../sequence'
7
- require_relative 'tidb/database_statements'
8
- require_relative 'tidb/schema_statements'
9
8
 
10
9
  ActiveRecord::ConnectionAdapters::Tidb.initial_setup
11
10
 
@@ -31,28 +30,7 @@ module ActiveRecord
31
30
  end
32
31
  end
33
32
 
34
-
35
-
36
33
  module ConnectionAdapters
37
- class Mysql2Adapter < AbstractMysqlAdapter
38
- ER_BAD_DB_ERROR = 1049
39
- ADAPTER_NAME = "Mysql2"
40
-
41
- include MySQL::DatabaseStatements
42
-
43
- class << self
44
- def new_client(config)
45
- Mysql2::Client.new(config)
46
- rescue Mysql2::Error => error
47
- if error.error_number == ConnectionAdapters::Mysql2Adapter::ER_BAD_DB_ERROR
48
- raise ActiveRecord::NoDatabaseError
49
- else
50
- raise ActiveRecord::ConnectionNotEstablished, error.message
51
- end
52
- end
53
- end
54
- end
55
-
56
34
  class TidbAdapter < Mysql2Adapter
57
35
  include ActiveRecord::Sequence::Adapter
58
36
  ADAPTER_NAME = 'Tidb'
@@ -121,6 +99,51 @@ module ActiveRecord
121
99
  rescue ActiveRecord::NoDatabaseError
122
100
  false
123
101
  end
102
+
103
+ def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = [])
104
+ sql, binds = to_sql_and_binds(arel, binds)
105
+ value = exec_insert(sql, name, binds, pk, sequence_name)
106
+ return id_value if id_value.present?
107
+
108
+ model = arel.ast.relation.instance_variable_get(:@klass)
109
+ pk_def = schema_cache.columns_hash(model.table_name)[pk]
110
+ if pk_def&.default_function && pk_def.default_function =~ /nextval/
111
+ query_value("SELECT #{pk_def.default_function.sub('nextval', 'lastval')}")
112
+ elsif model.sequence_name
113
+ ActiveRecord::Base.lastval(model.sequence_name)
114
+ else
115
+ last_inserted_id(value)
116
+ end
117
+ end
118
+ alias create insert
119
+
120
+ def new_column_from_field(_table_name, field)
121
+ 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
132
+ elsif default.to_s =~ /nextval/i
133
+ default_function = default
134
+ default = nil
135
+ end
136
+
137
+ MySQL::Column.new(
138
+ field[:Field],
139
+ default,
140
+ type_metadata,
141
+ field[:Null] == 'YES',
142
+ default_function,
143
+ collation: field[:Collation],
144
+ comment: field[:Comment].presence
145
+ )
146
+ end
124
147
  end
125
148
  end
126
149
  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 = '5.2.2'
4
+ TIDB_ADAPTER_VERSION = '6.1.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: 5.2.2
4
+ version: 6.1.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-23 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: '5.2'
19
+ version: '6.1'
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: '5.2'
26
+ version: '6.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mysql2
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -45,10 +45,6 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - ".buildkite/hooks/pre-command"
49
- - ".buildkite/pipeline.yml"
50
- - ".github/entrypoint.sh"
51
- - ".github/workflows/ci.yml"
52
48
  - ".gitignore"
53
49
  - Gemfile
54
50
  - Gemfile.lock
@@ -59,9 +55,7 @@ files:
59
55
  - bin/console
60
56
  - bin/setup
61
57
  - config.toml
62
- - lib/active_record/connection_adapters/tidb/database_statements.rb
63
58
  - lib/active_record/connection_adapters/tidb/database_tasks.rb
64
- - lib/active_record/connection_adapters/tidb/schema_statements.rb
65
59
  - lib/active_record/connection_adapters/tidb/setup.rb
66
60
  - lib/active_record/connection_adapters/tidb/type.rb
67
61
  - lib/active_record/connection_adapters/tidb_adapter.rb
@@ -72,7 +66,6 @@ files:
72
66
  - lib/active_record/sequence/schema_dumper.rb
73
67
  - lib/activerecord-tidb-adapter.rb
74
68
  - lib/version.rb
75
- - testing.sh
76
69
  homepage: https://github.com/pingcap/activerecord-tidb-adapter
77
70
  licenses:
78
71
  - Apache-2.0
@@ -1,10 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Place this in /etc/buildkite-agent/hooks/pre-command
4
- #
5
- # Needs to be `chown buildkite-agent` and `chmod +x`
6
-
7
- # RVM uses unbound variables and will fail without this
8
- set +u
9
-
10
- source /var/lib/buildkite-agent/.rvm/scripts/rvm
@@ -1,7 +0,0 @@
1
- env:
2
- MYSQL_HOST: 127.0.0.1
3
- MYSQL_USER: root
4
-
5
- steps:
6
- - command: "testing.sh"
7
- label: "Run TiDB ActiveRecord Adapter testing 5-2-stable"
@@ -1,16 +0,0 @@
1
- #!/bin/bash
2
- set -eu
3
- service supervisor start
4
-
5
- while sleep 60; do
6
- ps aux |grep tidb |grep -q -v grep
7
- TIDB_STATUS=$?
8
- ps aux |grep tikv |grep -q -v grep
9
- TIKV_STATUS=$?
10
- # If the greps above find anything, they exit with 0 status
11
- # If they are not both 0, then something is wrong
12
- if [ $TIDB_STATUS -ne 0 -o $TIKV_STATUS -ne 0 ]; then
13
- echo "One of the processes has already exited."
14
- exit 1
15
- fi
16
- done
@@ -1,35 +0,0 @@
1
- name: activerecord-tidb-adapter ci
2
-
3
- on:
4
- push:
5
- branches:
6
- - 5-2-stable
7
- paths-ignore:
8
- - 'README*.md'
9
- - 'docs/**'
10
- pull_request:
11
- branches:
12
- - 5-2-stable
13
- paths-ignore:
14
- - 'README*.md'
15
- - 'docs/**'
16
-
17
- jobs:
18
- build:
19
- if: ${{ !contains(github.event.commits[0].message, '[skip ci]') }}
20
- runs-on: ubuntu-latest
21
- services:
22
- tidb:
23
- image: hawkingrei/tind:v5.1.0
24
- options: --entrypoint /entrypoint.sh
25
- env:
26
- TIDB_VERSION: v5.1.0
27
- ports: ["4000:4000"]
28
- steps:
29
- - uses: actions/checkout@v2
30
- - uses: ruby/setup-ruby@v1
31
- with:
32
- ruby-version: 2.7
33
- bundler-cache: true
34
- - run: sleep 30 && MYSQL_USER=root MYSQL_HOST=127.0.0.1 MYSQL_PORT=4000 tidb=1 ARCONN=tidb bundle exec rake db:tidb:build
35
- - run: sleep 10 && MYSQL_USER=root MYSQL_HOST=127.0.0.1 MYSQL_PORT=4000 tidb=1 ARCONN=tidb bundle exec rake test:tidb
@@ -1,19 +0,0 @@
1
- require 'active_record/connection_adapters/abstract/database_statements'
2
-
3
- ActiveRecord::ConnectionAdapters::DatabaseStatements.class_eval do
4
- def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = [])
5
- sql, binds = to_sql_and_binds(arel, binds)
6
- value = exec_insert(sql, name, binds, pk, sequence_name)
7
-
8
- return id_value if id_value.present?
9
- return last_inserted_id(value) if arel.is_a?(String)
10
- table_name = arel.ast.relation.table_name
11
- pk_def = schema_cache.columns_hash(table_name)[pk]
12
- if pk_def&.default_function && pk_def.default_function =~ /nextval/
13
- query_value("SELECT #{pk_def.default_function.sub('nextval', 'lastval')}")
14
- else
15
- last_inserted_id(value)
16
- end
17
- end
18
- alias create insert
19
- end
@@ -1,28 +0,0 @@
1
- require 'pry'
2
- require 'active_record/connection_adapters/mysql/schema_statements'
3
-
4
-
5
- ActiveRecord::ConnectionAdapters::MySQL::SchemaStatements.class_eval do
6
- def new_column_from_field(table_name, field)
7
- type_metadata = fetch_type_metadata(field[:Type], field[:Extra])
8
- if type_metadata.type == :datetime && /\ACURRENT_TIMESTAMP(?:\([0-6]?\))?\z/i.match?(field[:Default])
9
- default, default_function = nil, field[:Default]
10
- elsif field[:Default].to_s =~ /nextval/i
11
- default_function = field[:Default]
12
- default = nil
13
- else
14
- default, default_function = field[:Default], nil
15
- end
16
-
17
- ActiveRecord::ConnectionAdapters::MySQL::Column.new(
18
- field[:Field],
19
- default,
20
- type_metadata,
21
- field[:Null] == "YES",
22
- table_name,
23
- default_function,
24
- field[:Collation],
25
- comment: field[:Comment].presence
26
- )
27
- end
28
- end
data/testing.sh DELETED
@@ -1,14 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -eo pipefail
4
-
5
- bundle config set --local path '/tmp/buildkite-cache'
6
-
7
- echo "Setup gem mirror"
8
- bundle config mirror.https://rubygems.org https://gems.ruby-china.com
9
-
10
- echo "Bundle install"
11
- bundle install
12
-
13
- echo "Setup database for testing"
14
- tidb=1 ARCONN=tidb bundle exec rake db:tidb:rebuild && tidb=1 ARCONN=tidb bundle exec rake test:tidb