activerecord-tidb-adapter 0.4.0 → 0.5.0

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
2
  SHA256:
3
- metadata.gz: 85ed982e6735cfcb567e2d863975ba8f56e98dd6243578394e2ca01dc07ca91a
4
- data.tar.gz: c7aefb6293698e59ce8ff6812b156070622c6ed7c58689e39c4eca5946309959
3
+ metadata.gz: 7e086031695fe37ee336da6d8722b947018501e8e3ce90051d00b83d7aebc742
4
+ data.tar.gz: af2a51ca724563cc076f5bf0ef018eb0bd8bb15a756947c316e374f30b100396
5
5
  SHA512:
6
- metadata.gz: af4ea51bd264d25cd621e3c95438fd9fd3c7df8b2dea533172cbeb0e07110e661dc68b0d294c23a1420e2b9c0a74334b14c46213d59425764a37336702d17034
7
- data.tar.gz: d07ec9fa2f944d6832c7f70287d4583073ea633b7c8364936801e555ac5592a4c5d21b18e9fff5b12a2599b4b8bfc637c5163cbb0b6604e0af1c5b388bc7f70f
6
+ metadata.gz: f8e0c432e30009832966b1a70d3a2842e9b64c9fa417c3744952c0d1feb6d64a956308496dcab19ba36ac2c9da7e48a0fa94d69ad14fa4a5d2849781b6fa8bcd
7
+ data.tar.gz: 844d1511bb454844e4d179b7c519dbcac9398a9e4df6ad3df85f8396d1f7b687ef3f13a77330f1126c4b6479fb8fe1f472c5feae8b3002f386e964626d005120
data/Gemfile.lock CHANGED
@@ -1,6 +1,6 @@
1
1
  GIT
2
2
  remote: https://github.com/tidb-incubator/rails.git
3
- revision: e377e0dc16e9841a048ec7eab2666c06155b6a0c
3
+ revision: e2a3d3fb2ee24c709b9f32221fbcb66cfda5acfc
4
4
  branch: 6-1-stable
5
5
  specs:
6
6
  actioncable (6.1.4)
@@ -87,7 +87,7 @@ GIT
87
87
  PATH
88
88
  remote: .
89
89
  specs:
90
- activerecord-tidb-adapter (0.4.0)
90
+ activerecord-tidb-adapter (0.5.0)
91
91
  activerecord (~> 6.1)
92
92
  mysql2
93
93
 
@@ -105,7 +105,7 @@ GEM
105
105
  activesupport (>= 5.0)
106
106
  i18n (1.8.10)
107
107
  concurrent-ruby (~> 1.0)
108
- loofah (2.11.0)
108
+ loofah (2.12.0)
109
109
  crass (~> 1.0.2)
110
110
  nokogiri (>= 1.5.9)
111
111
  mail (2.7.1)
@@ -118,6 +118,8 @@ GEM
118
118
  minitest (~> 5.0)
119
119
  mysql2 (0.5.3)
120
120
  nio4r (2.5.8)
121
+ nokogiri (1.12.3-x86_64-darwin)
122
+ racc (~> 1.4)
121
123
  nokogiri (1.12.3-x86_64-linux)
122
124
  racc (~> 1.4)
123
125
  parallel (1.20.1)
@@ -140,16 +142,16 @@ GEM
140
142
  rake (13.0.6)
141
143
  regexp_parser (2.1.1)
142
144
  rexml (3.2.5)
143
- rubocop (1.18.4)
145
+ rubocop (1.19.0)
144
146
  parallel (~> 1.10)
145
147
  parser (>= 3.0.0.0)
146
148
  rainbow (>= 2.2.2, < 4.0)
147
149
  regexp_parser (>= 1.8, < 3.0)
148
150
  rexml
149
- rubocop-ast (>= 1.8.0, < 2.0)
151
+ rubocop-ast (>= 1.9.1, < 2.0)
150
152
  ruby-progressbar (~> 1.7)
151
153
  unicode-display_width (>= 1.4.0, < 3.0)
152
- rubocop-ast (1.8.0)
154
+ rubocop-ast (1.10.0)
153
155
  parser (>= 3.0.1.1)
154
156
  ruby-progressbar (1.11.0)
155
157
  sprockets (4.0.2)
data/README.md CHANGED
@@ -140,13 +140,19 @@ MYSQL_USER=root MYSQL_HOST=127.0.0.1 MYSQL_PORT=4000 tidb=1 ARCONN=tidb bundle e
140
140
 
141
141
  ```
142
142
 
143
- run tidb adapter tests
143
+ run tidb adapter tests and activerecord buildin tests
144
144
 
145
145
  ```
146
- MYSQL_USER=root MYSQL_HOST=127.0.0.1 MYSQL_PORT=4000 tidb=1 ARCONN=tidb bundle exec rake test:idb
146
+ MYSQL_USER=root MYSQL_HOST=127.0.0.1 MYSQL_PORT=4000 tidb=1 ARCONN=tidb bundle exec rake test:tidb
147
147
 
148
148
  ```
149
149
 
150
+ run **ONLY** tidb adapter tests using `ONLY_TEST_TIDB` env:
151
+
152
+ ```
153
+ ONLY_TEST_TIDB=1 MYSQL_USER=root MYSQL_HOST=127.0.0.1 MYSQL_PORT=4000 tidb=1 ARCONN=tidb bundle exec rake test:tidb
154
+ ```
155
+
150
156
  ## Contributing
151
157
 
152
158
  Bug reports and pull requests are welcome on GitHub at https://github.com/pingcap/activerecord-tidb-adapter.
@@ -9,9 +9,9 @@ require_relative '../sequence'
9
9
  ActiveRecord::ConnectionAdapters::Tidb.initial_setup
10
10
 
11
11
  module ActiveRecord
12
- module ConnectionHandling #:nodoc:
12
+ module ConnectionHandling # :nodoc:
13
13
  # Establishes a connection to the database that's used by all Active Record objects.
14
- def tidb_connection(config) #:nodoc:
14
+ def tidb_connection(config) # :nodoc:
15
15
  config = config.symbolize_keys
16
16
  config[:flags] ||= 0
17
17
 
@@ -100,6 +100,23 @@ module ActiveRecord
100
100
  false
101
101
  end
102
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
+
103
120
  def new_column_from_field(_table_name, field)
104
121
  type_metadata = fetch_type_metadata(field[:Type], field[:Extra])
105
122
  default = field[:Default]
@@ -37,9 +37,14 @@ module ActiveRecord
37
37
 
38
38
  def drop_sequence(name)
39
39
  name = quote_column_name(name)
40
- sql = "DROP SEQUENCE #{name}"
40
+ sql = "DROP SEQUENCE IF EXISTS #{name}"
41
41
  execute(sql)
42
42
  end
43
+
44
+ def recreate_sequence(name, options = {})
45
+ drop_sequence(name)
46
+ create_sequence(name, options)
47
+ end
43
48
  end
44
49
  end
45
50
  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.4.0'
4
+ TIDB_ADAPTER_VERSION = '0.5.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.4.0
4
+ version: 0.5.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-15 00:00:00.000000000 Z
11
+ date: 2021-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord