activerecord-tidb-adapter 5.2.0 → 5.2.2
Sign up to get free protection for your applications and to get access to all the features.
- 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 +35 -0
- data/Gemfile.lock +2 -2
- data/README.md +1 -1
- data/lib/active_record/connection_adapters/tidb/database_statements.rb +19 -0
- data/lib/active_record/connection_adapters/tidb/schema_statements.rb +28 -0
- data/lib/active_record/connection_adapters/tidb_adapter.rb +2 -38
- data/lib/version.rb +1 -1
- data/testing.sh +14 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ec81c5f43cb98b0fe8fb61484ea7b0050a84cb8c7caac6d25e314d58f5f1be0
|
4
|
+
data.tar.gz: 4a99eafd9d2f53885e063cc89af6ecf2afce3506e0f9b118a999e52c5fe93e71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66909adaf233af63fb1f7f251cb8f11ba4a484c80e7646c9202c5636a7477575880f85927e01403ce26f8ebaa4a88c5eea6ffa1052a5a34d4e8b12d18f5cbb86
|
7
|
+
data.tar.gz: 8ad7289243de4d4f4e1b34d759be041f33c5b02d6b99428e9fc09ad918baa021751d708adc335c126495dce29eae9fca61a63cf7533711c7cd88cb6caf3511a3
|
@@ -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,35 @@
|
|
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
|
data/Gemfile.lock
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
GIT
|
2
2
|
remote: https://github.com/pingcap/rails.git
|
3
|
-
revision:
|
3
|
+
revision: a1adbde17b229e9131d40787ee4342c1180afb36
|
4
4
|
branch: 5-2-stable
|
5
5
|
specs:
|
6
6
|
actioncable (5.2.6)
|
@@ -67,7 +67,7 @@ GIT
|
|
67
67
|
PATH
|
68
68
|
remote: .
|
69
69
|
specs:
|
70
|
-
activerecord-tidb-adapter (5.2.
|
70
|
+
activerecord-tidb-adapter (5.2.2)
|
71
71
|
activerecord (~> 5.2)
|
72
72
|
mysql2
|
73
73
|
|
data/README.md
CHANGED
@@ -0,0 +1,19 @@
|
|
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
|
@@ -0,0 +1,28 @@
|
|
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
|
@@ -4,6 +4,8 @@ require 'active_record/connection_adapters/mysql2_adapter'
|
|
4
4
|
require 'active_record/connection_adapters/tidb/setup'
|
5
5
|
require_relative '../../version'
|
6
6
|
require_relative '../sequence'
|
7
|
+
require_relative 'tidb/database_statements'
|
8
|
+
require_relative 'tidb/schema_statements'
|
7
9
|
|
8
10
|
ActiveRecord::ConnectionAdapters::Tidb.initial_setup
|
9
11
|
|
@@ -119,44 +121,6 @@ module ActiveRecord
|
|
119
121
|
rescue ActiveRecord::NoDatabaseError
|
120
122
|
false
|
121
123
|
end
|
122
|
-
|
123
|
-
def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = [])
|
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)
|
139
|
-
type_metadata = fetch_type_metadata(field[:Type], field[:Extra])
|
140
|
-
if type_metadata.type == :datetime && /\ACURRENT_TIMESTAMP(?:\([0-6]?\))?\z/i.match?(field[:Default])
|
141
|
-
default, default_function = nil, field[:Default]
|
142
|
-
elsif default.to_s =~ /nextval/i
|
143
|
-
default_function = default
|
144
|
-
default = nil
|
145
|
-
else
|
146
|
-
default, default_function = field[:Default], nil
|
147
|
-
end
|
148
|
-
|
149
|
-
MySQL::Column.new(
|
150
|
-
field[:Field],
|
151
|
-
default,
|
152
|
-
type_metadata,
|
153
|
-
field[:Null] == "YES",
|
154
|
-
table_name,
|
155
|
-
default_function,
|
156
|
-
field[:Collation],
|
157
|
-
comment: field[:Comment].presence
|
158
|
-
)
|
159
|
-
end
|
160
124
|
end
|
161
125
|
end
|
162
126
|
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: 5.2.
|
4
|
+
version: 5.2.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-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -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
|