activerecord-tidb-adapter 5.2.0 → 6.1.2
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 +4 -4
- data/.buildkite/hooks/pre-command +10 -0
- data/.buildkite/pipeline.yml +7 -0
- data/.github/entrypoint.sh +16 -0
- data/.github/workflows/ci.yml +90 -0
- data/Gemfile +1 -5
- data/Gemfile.lock +73 -58
- data/README.md +7 -2
- data/activerecord-tidb-adapter.gemspec +2 -2
- data/config.toml +1 -0
- data/lib/active_record/connection_adapters/tidb/database_statements.rb +18 -0
- data/lib/active_record/connection_adapters/tidb/schema_statements.rb +71 -0
- data/lib/active_record/connection_adapters/tidb_adapter.rb +17 -45
- data/lib/version.rb +1 -1
- data/testing.sh +14 -0
- metadata +12 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7a83c6f47ef9ff4341b013e4940eb694d3e12eb51c5965c0ceb1ab04e00f6e6
|
4
|
+
data.tar.gz: 14eab9c135c9c948fde48803e7e630fe6b570e080207bb6adf41b669aeebd7bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c3d8267b1985a86b3b1c9665d66a6c701f6da6eac9dd937bad83493c430c7abb1c38dc773370144ed8ebbe76bb6d1651615eaaf86ebe0f188ac5a04e8cb294f
|
7
|
+
data.tar.gz: ef90da031efbe077422fcb3f19acf9abb73129fce6b6ab2c02ff103e496a5812db761e470731c9574b56af35a43edcfa12762da137d629b04cd251a98f3496d8
|
@@ -0,0 +1,16 @@
|
|
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
|
@@ -0,0 +1,90 @@
|
|
1
|
+
name: activerecord-tidb-adapter 6-1
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- 6-1-stable
|
7
|
+
paths-ignore:
|
8
|
+
- 'README*.md'
|
9
|
+
- 'docs/**'
|
10
|
+
pull_request:
|
11
|
+
branches:
|
12
|
+
- 6-1-stable
|
13
|
+
paths-ignore:
|
14
|
+
- 'README*.md'
|
15
|
+
- 'docs/**'
|
16
|
+
|
17
|
+
jobs:
|
18
|
+
tidb510:
|
19
|
+
if: ${{ !contains(github.event.commits[0].message, '[skip ci]') }}
|
20
|
+
runs-on: ubuntu-latest
|
21
|
+
services:
|
22
|
+
tidb:
|
23
|
+
image: hooopo/tidb-playground:v5.1.0
|
24
|
+
env:
|
25
|
+
TIDB_VERSION: v5.1.0
|
26
|
+
ports: ["4000:4000"]
|
27
|
+
steps:
|
28
|
+
- uses: actions/checkout@v2
|
29
|
+
- uses: ruby/setup-ruby@v1
|
30
|
+
with:
|
31
|
+
ruby-version: 2.7
|
32
|
+
bundler-cache: true
|
33
|
+
- 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
|
34
|
+
- run: sleep 10 && MYSQL_USER=root MYSQL_HOST=127.0.0.1 MYSQL_PORT=4000 tidb=1 ARCONN=tidb bundle exec rake test:tidb
|
35
|
+
|
36
|
+
tidb503:
|
37
|
+
if: ${{ !contains(github.event.commits[0].message, '[skip ci]') }}
|
38
|
+
runs-on: ubuntu-latest
|
39
|
+
services:
|
40
|
+
tidb:
|
41
|
+
image: hooopo/tidb-playground:v5.0.3
|
42
|
+
env:
|
43
|
+
TIDB_VERSION: v5.0.3
|
44
|
+
ports: ["4000:4000"]
|
45
|
+
steps:
|
46
|
+
- uses: actions/checkout@v2
|
47
|
+
- uses: ruby/setup-ruby@v1
|
48
|
+
with:
|
49
|
+
ruby-version: 2.7
|
50
|
+
bundler-cache: true
|
51
|
+
- 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
|
52
|
+
- run: mysql --host 127.0.0.1 --database activerecord_unittest --port 4000 -u root -e 'set @@global.tidb_enable_change_column_type = 1'
|
53
|
+
- run: mysql --host 127.0.0.1 --database activerecord_unittest2 --port 4000 -u root -e 'set @@global.tidb_enable_change_column_type = 1'
|
54
|
+
- run: sleep 10 && MYSQL_USER=root MYSQL_HOST=127.0.0.1 MYSQL_PORT=4000 tidb=1 ARCONN=tidb bundle exec rake test:tidb
|
55
|
+
|
56
|
+
tidb511:
|
57
|
+
if: ${{ !contains(github.event.commits[0].message, '[skip ci]') }}
|
58
|
+
runs-on: ubuntu-latest
|
59
|
+
services:
|
60
|
+
tidb:
|
61
|
+
image: hooopo/tidb-playground:v5.1.1
|
62
|
+
env:
|
63
|
+
TIDB_VERSION: v5.1.1
|
64
|
+
ports: ["4000:4000"]
|
65
|
+
steps:
|
66
|
+
- uses: actions/checkout@v2
|
67
|
+
- uses: ruby/setup-ruby@v1
|
68
|
+
with:
|
69
|
+
ruby-version: 2.7
|
70
|
+
bundler-cache: true
|
71
|
+
- 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
|
72
|
+
- run: sleep 10 && MYSQL_USER=root MYSQL_HOST=127.0.0.1 MYSQL_PORT=4000 tidb=1 ARCONN=tidb bundle exec rake test:tidb
|
73
|
+
|
74
|
+
tidb520:
|
75
|
+
if: ${{ !contains(github.event.commits[0].message, '[skip ci]') }}
|
76
|
+
runs-on: ubuntu-latest
|
77
|
+
services:
|
78
|
+
tidb:
|
79
|
+
image: hooopo/tidb-playground:v5.2.0
|
80
|
+
env:
|
81
|
+
TIDB_VERSION: v5.2.0
|
82
|
+
ports: ["4000:4000"]
|
83
|
+
steps:
|
84
|
+
- uses: actions/checkout@v2
|
85
|
+
- uses: ruby/setup-ruby@v1
|
86
|
+
with:
|
87
|
+
ruby-version: 2.7
|
88
|
+
bundler-cache: true
|
89
|
+
- 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
|
90
|
+
- run: sleep 10 && MYSQL_USER=root MYSQL_HOST=127.0.0.1 MYSQL_PORT=4000 tidb=1 ARCONN=tidb bundle exec rake test:tidb
|
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: '
|
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:
|
4
|
-
branch:
|
3
|
+
revision: e2a3d3fb2ee24c709b9f32221fbcb66cfda5acfc
|
4
|
+
branch: 6-1-stable
|
5
5
|
specs:
|
6
|
-
actioncable (
|
7
|
-
actionpack (=
|
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
|
-
|
11
|
-
actionpack (=
|
12
|
-
|
13
|
-
|
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 (
|
17
|
-
actionview (=
|
18
|
-
activesupport (=
|
19
|
-
rack (~> 2.0, >= 2.0.
|
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
|
23
|
-
|
24
|
-
|
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.
|
29
|
-
activejob (
|
30
|
-
activesupport (=
|
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 (
|
33
|
-
activesupport (=
|
34
|
-
activerecord (
|
35
|
-
activemodel (=
|
36
|
-
activesupport (=
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
activerecord (=
|
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
|
-
|
58
|
+
mini_mime (>= 1.1.0)
|
59
|
+
activesupport (6.1.4)
|
43
60
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
44
|
-
i18n (>=
|
45
|
-
minitest (
|
46
|
-
tzinfo (~>
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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 (
|
61
|
-
actionpack (=
|
62
|
-
activesupport (=
|
80
|
+
railties (6.1.4)
|
81
|
+
actionpack (= 6.1.4)
|
82
|
+
activesupport (= 6.1.4)
|
63
83
|
method_source
|
64
|
-
rake (>= 0.
|
65
|
-
thor (
|
84
|
+
rake (>= 0.13)
|
85
|
+
thor (~> 1.0)
|
66
86
|
|
67
87
|
PATH
|
68
88
|
remote: .
|
69
89
|
specs:
|
70
|
-
activerecord-tidb-adapter (
|
71
|
-
activerecord (~>
|
90
|
+
activerecord-tidb-adapter (6.1.2)
|
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
|
-
|
150
|
-
|
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
@@ -1,6 +1,7 @@
|
|
1
1
|
# ActiveRecord TiDB Adapter
|
2
2
|
|
3
|
-
TiDB adapter for ActiveRecord 5
|
3
|
+
TiDB adapter for ActiveRecord 5.2, 6.1 and 7.0
|
4
|
+
This is a lightweight extension of the mysql2 adapter that establishes compatibility with [TiDB](https://github.com/pingcap/tidb).
|
4
5
|
|
5
6
|
|
6
7
|
## Installation
|
@@ -8,9 +9,13 @@ TiDB adapter for ActiveRecord 5 and 6. This is a lightweight extension of the my
|
|
8
9
|
Add this line to your application's Gemfile:
|
9
10
|
|
10
11
|
```ruby
|
11
|
-
gem 'activerecord-tidb-adapter'
|
12
|
+
gem 'activerecord-tidb-adapter', "~> 6.1.0"
|
12
13
|
```
|
13
14
|
|
15
|
+
If you're using Rails 5.2, use the 5.2.x versions of this gem.
|
16
|
+
|
17
|
+
If you're using Rails 7.0, use the 7.0.x versions of this gem.
|
18
|
+
|
14
19
|
And then execute:
|
15
20
|
|
16
21
|
$ bundle install
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = 'Allows the use of TiDB as a backend for ActiveRecord and Rails apps.'
|
13
13
|
spec.homepage = 'https://github.com/pingcap/activerecord-tidb-adapter'
|
14
14
|
spec.license = 'Apache-2.0'
|
15
|
-
spec.required_ruby_version = '>= 2.
|
15
|
+
spec.required_ruby_version = '>= 2.5.0'
|
16
16
|
|
17
17
|
# spec.metadata["allowed_push_host"] = "TODO: Set to 'https://mygemserver.com'"
|
18
18
|
|
@@ -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', '~>
|
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
|
data/config.toml
CHANGED
@@ -0,0 +1,18 @@
|
|
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
|
+
return id_value if id_value.present?
|
8
|
+
return last_inserted_id(value) if arel.is_a?(String)
|
9
|
+
model = arel.ast.relation.instance_variable_get(:@klass)
|
10
|
+
pk_def = schema_cache.columns_hash(model.table_name)[pk]
|
11
|
+
if pk_def&.default_function && pk_def.default_function =~ /nextval/
|
12
|
+
query_value("SELECT #{pk_def.default_function.sub('nextval', 'lastval')}")
|
13
|
+
else
|
14
|
+
last_inserted_id(value)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
alias create insert
|
18
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'active_record/connection_adapters/mysql/schema_statements'
|
2
|
+
|
3
|
+
ActiveRecord::ConnectionAdapters::MySQL::SchemaStatements.class_eval do
|
4
|
+
def indexes(table_name)
|
5
|
+
indexes = []
|
6
|
+
current_index = nil
|
7
|
+
execute_and_free("SHOW KEYS FROM #{quote_table_name(table_name)}", "SCHEMA") do |result|
|
8
|
+
each_hash(result) do |row|
|
9
|
+
if current_index != row[:Key_name]
|
10
|
+
next if row[:Key_name] == "PRIMARY" # skip the primary key
|
11
|
+
current_index = row[:Key_name]
|
12
|
+
|
13
|
+
mysql_index_type = row[:Index_type].downcase.to_sym
|
14
|
+
case mysql_index_type
|
15
|
+
when :fulltext, :spatial
|
16
|
+
index_type = mysql_index_type
|
17
|
+
when :btree, :hash
|
18
|
+
index_using = mysql_index_type
|
19
|
+
end
|
20
|
+
|
21
|
+
indexes << [
|
22
|
+
row[:Table],
|
23
|
+
row[:Key_name],
|
24
|
+
row[:Non_unique].to_i == 0,
|
25
|
+
[],
|
26
|
+
lengths: {},
|
27
|
+
orders: {},
|
28
|
+
type: index_type,
|
29
|
+
using: index_using,
|
30
|
+
comment: row[:Index_comment].presence
|
31
|
+
]
|
32
|
+
end
|
33
|
+
|
34
|
+
# FIX https://github.com/pingcap/tidb/issues/26110 for older version of TiDB
|
35
|
+
row[:Expression] = nil if row[:Expression] == 'NULL'
|
36
|
+
|
37
|
+
if row[:Expression]
|
38
|
+
expression = row[:Expression]
|
39
|
+
expression = +"(#{expression})" unless expression.start_with?("(")
|
40
|
+
indexes.last[-2] << expression
|
41
|
+
indexes.last[-1][:expressions] ||= {}
|
42
|
+
indexes.last[-1][:expressions][expression] = expression
|
43
|
+
indexes.last[-1][:orders][expression] = :desc if row[:Collation] == "D"
|
44
|
+
else
|
45
|
+
indexes.last[-2] << row[:Column_name]
|
46
|
+
indexes.last[-1][:lengths][row[:Column_name]] = row[:Sub_part].to_i if row[:Sub_part]
|
47
|
+
indexes.last[-1][:orders][row[:Column_name]] = :desc if row[:Collation] == "D"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
indexes.map do |index|
|
53
|
+
options = index.pop
|
54
|
+
|
55
|
+
if expressions = options.delete(:expressions)
|
56
|
+
orders = options.delete(:orders)
|
57
|
+
lengths = options.delete(:lengths)
|
58
|
+
|
59
|
+
columns = index[-1].map { |name|
|
60
|
+
[ name.to_sym, expressions[name] || +quote_column_name(name) ]
|
61
|
+
}.to_h
|
62
|
+
|
63
|
+
index[-1] = add_options_for_index_columns(
|
64
|
+
columns, order: orders, length: lengths
|
65
|
+
).values.join(", ")
|
66
|
+
end
|
67
|
+
|
68
|
+
ActiveRecord::ConnectionAdapters::IndexDefinition.new(*index, **options)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -1,9 +1,12 @@
|
|
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'
|
8
|
+
require_relative 'tidb/schema_statements'
|
9
|
+
require_relative 'tidb/database_statements'
|
7
10
|
|
8
11
|
ActiveRecord::ConnectionAdapters::Tidb.initial_setup
|
9
12
|
|
@@ -29,28 +32,7 @@ module ActiveRecord
|
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
32
|
-
|
33
|
-
|
34
35
|
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
|
-
|
54
36
|
class TidbAdapter < Mysql2Adapter
|
55
37
|
include ActiveRecord::Sequence::Adapter
|
56
38
|
ADAPTER_NAME = 'Tidb'
|
@@ -85,7 +67,7 @@ module ActiveRecord
|
|
85
67
|
end
|
86
68
|
|
87
69
|
def supports_expression_index?
|
88
|
-
|
70
|
+
false
|
89
71
|
end
|
90
72
|
|
91
73
|
def supports_common_table_expressions?
|
@@ -120,40 +102,30 @@ module ActiveRecord
|
|
120
102
|
false
|
121
103
|
end
|
122
104
|
|
123
|
-
def
|
124
|
-
sql, binds = to_sql_and_binds(arel, binds)
|
125
|
-
value = exec_insert(sql, name, binds, pk, sequence_name)
|
126
|
-
return id_value if id_value.present?
|
127
|
-
|
128
|
-
table_name = arel.ast.relation.table_name
|
129
|
-
pk_def = schema_cache.columns_hash(table_name)[pk]
|
130
|
-
if pk_def&.default_function && pk_def.default_function =~ /nextval/
|
131
|
-
query_value("SELECT #{pk_def.default_function.sub('nextval', 'lastval')}")
|
132
|
-
else
|
133
|
-
last_inserted_id(value)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
alias create insert
|
137
|
-
|
138
|
-
def new_column_from_field(table_name, field)
|
105
|
+
def new_column_from_field(_table_name, field)
|
139
106
|
type_metadata = fetch_type_metadata(field[:Type], field[:Extra])
|
140
|
-
|
141
|
-
|
107
|
+
default = field[:Default]
|
108
|
+
default_function = nil
|
109
|
+
|
110
|
+
if type_metadata.type == :datetime && /\ACURRENT_TIMESTAMP(?:\([0-6]?\))?\z/i.match?(default)
|
111
|
+
default_function = default
|
112
|
+
default = nil
|
113
|
+
elsif type_metadata.extra == 'DEFAULT_GENERATED'
|
114
|
+
default = +"(#{default})" unless default.start_with?('(')
|
115
|
+
default_function = default
|
116
|
+
default = nil
|
142
117
|
elsif default.to_s =~ /nextval/i
|
143
118
|
default_function = default
|
144
119
|
default = nil
|
145
|
-
else
|
146
|
-
default, default_function = field[:Default], nil
|
147
120
|
end
|
148
121
|
|
149
122
|
MySQL::Column.new(
|
150
123
|
field[:Field],
|
151
124
|
default,
|
152
125
|
type_metadata,
|
153
|
-
field[:Null] ==
|
154
|
-
table_name,
|
126
|
+
field[:Null] == 'YES',
|
155
127
|
default_function,
|
156
|
-
field[:Collation],
|
128
|
+
collation: field[:Collation],
|
157
129
|
comment: field[:Comment].presence
|
158
130
|
)
|
159
131
|
end
|
data/lib/version.rb
CHANGED
data/testing.sh
ADDED
@@ -0,0 +1,14 @@
|
|
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
|
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:
|
4
|
+
version: 6.1.2
|
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
|
11
|
+
date: 2021-09-08 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: '
|
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: '
|
26
|
+
version: '6.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mysql2
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,6 +45,10 @@ 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"
|
48
52
|
- ".gitignore"
|
49
53
|
- Gemfile
|
50
54
|
- Gemfile.lock
|
@@ -55,7 +59,9 @@ files:
|
|
55
59
|
- bin/console
|
56
60
|
- bin/setup
|
57
61
|
- config.toml
|
62
|
+
- lib/active_record/connection_adapters/tidb/database_statements.rb
|
58
63
|
- lib/active_record/connection_adapters/tidb/database_tasks.rb
|
64
|
+
- lib/active_record/connection_adapters/tidb/schema_statements.rb
|
59
65
|
- lib/active_record/connection_adapters/tidb/setup.rb
|
60
66
|
- lib/active_record/connection_adapters/tidb/type.rb
|
61
67
|
- lib/active_record/connection_adapters/tidb_adapter.rb
|
@@ -66,6 +72,7 @@ files:
|
|
66
72
|
- lib/active_record/sequence/schema_dumper.rb
|
67
73
|
- lib/activerecord-tidb-adapter.rb
|
68
74
|
- lib/version.rb
|
75
|
+
- testing.sh
|
69
76
|
homepage: https://github.com/pingcap/activerecord-tidb-adapter
|
70
77
|
licenses:
|
71
78
|
- Apache-2.0
|
@@ -80,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
87
|
requirements:
|
81
88
|
- - ">="
|
82
89
|
- !ruby/object:Gem::Version
|
83
|
-
version: 2.
|
90
|
+
version: 2.5.0
|
84
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
92
|
requirements:
|
86
93
|
- - ">="
|