composite_primary_keys 12.0.6 → 12.0.7

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.

Potentially problematic release.


This version of composite_primary_keys might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea522edb09ab0dfd60a25bb34aa7c31a50f1afc2260b54189338a694dce48c5b
4
- data.tar.gz: 5aefc2529dbfe80f7453ad75e2d3043fb329dc8294ac80f56ef2ce60988d8d45
3
+ metadata.gz: 9669e29673330db679efb20ca257d87ce1cdad3d6fe69681a54ac706a0cd5f82
4
+ data.tar.gz: db2ba7fcc0f91b8cd6c54c177dd5ca9d7cb7d04b47f1ec42e43691283a1f16d1
5
5
  SHA512:
6
- metadata.gz: f482042e909cbd80341bb609387d41fe82236d82c9f26aa5742e0c4ce470eb873ced0b48a461ec3836b361e0075c9c831f75e2f69023787738e6cca0e5a34026
7
- data.tar.gz: 649981635ecf30e0a94dfd811230395af0c0ab1111beec027fc9787d5185e57572f2b0677f8e4e88f01cf2cc784d1d0a2ccbd04ae30898ee2e860a9950a5e355
6
+ metadata.gz: 6bfb9ac058f43b9e18499e7517029e41278272f91955058eaf87d3ecac4649906e84ee9e01a8b6466128cfe998bfe94eec6fbb7e9f0d1945a3e9a749a6990a93
7
+ data.tar.gz: 435cb41a8e3499508285444be01f8c585c747f98a0c6174353ac31f3ed147a8f165478dfce8bd975a10142d7357bdcee7121f9726ced186ceb2062e0bde36625
data/History.rdoc CHANGED
@@ -1,3 +1,9 @@
1
+ == 12.0.7 (2021-02-15)
2
+ * Switch to GitHub actions (ta1kt0me)
3
+ * Fix MySQL/MariaDB query cache issue bug introduced in version 12.0.3 - see #539 (Charlie Savage)
4
+ * Do a better job of supporting composite keys with an auto incrementing field for
5
+ MySQL and MariaDB (Charlie Savage)
6
+
1
7
  == 12.0.6 (2021-01-04)
2
8
  * Fix issue when calling in_batches without a block (Charlie Savage)
3
9
 
@@ -62,6 +62,7 @@ require 'active_record/nested_attributes'
62
62
  require 'active_record/connection_adapters/abstract/database_statements'
63
63
  require 'active_record/connection_adapters/abstract_adapter'
64
64
  require 'active_record/connection_adapters/postgresql/database_statements'
65
+ require 'active_record/connection_adapters/mysql/database_statements'
65
66
 
66
67
  require 'active_record/relation/where_clause'
67
68
 
@@ -99,7 +100,7 @@ require_relative 'composite_primary_keys/nested_attributes'
99
100
 
100
101
  require_relative 'composite_primary_keys/connection_adapters/abstract/database_statements'
101
102
  require_relative 'composite_primary_keys/connection_adapters/abstract_adapter'
102
- require_relative 'composite_primary_keys/connection_adapters/mysql/database_statements'
103
+ #require_relative 'composite_primary_keys/connection_adapters/mysql/database_statements'
103
104
  require_relative 'composite_primary_keys/connection_adapters/postgresql/database_statements'
104
105
  require_relative 'composite_primary_keys/connection_adapters/sqlserver/database_statements'
105
106
 
@@ -5,16 +5,31 @@ module ActiveRecord
5
5
  sql, binds = to_sql_and_binds(arel, binds)
6
6
  value = exec_insert(sql, name, binds, pk, sequence_name)
7
7
 
8
+ return id_value if id_value
9
+
8
10
  if pk.is_a?(Array) && !value.empty?
9
11
  # This is a CPK model and the query result is not empty. Thus we can figure out the new ids for each
10
12
  # auto incremented field
11
- id_value || pk.map {|key| value.first[key]}
13
+ pk.map {|key| value.first[key]}
12
14
  elsif pk.is_a?(Array)
13
- # This is CPK, but we don't know what autoincremented fields were updated. So return nil, which means
14
- # the existing id_value of the model will be used.
15
- id_value || Array.new(pk.size)
15
+ # This is CPK, but we don't know what autoincremented fields were updated.
16
+ result = Array.new(pk.size)
17
+
18
+ # Is there an autoincrementing field?
19
+ auto_key = pk.find do |key|
20
+ attribute = arel.ast.relation[key]
21
+ column = column_for_attribute(attribute)
22
+ if column.respond_to?(:auto_increment?)
23
+ column.auto_increment?
24
+ end
25
+ end
26
+
27
+ if auto_key
28
+ result[pk.index(auto_key)] = last_inserted_id(value)
29
+ end
30
+ result
16
31
  else
17
- id_value || last_inserted_id(value)
32
+ last_inserted_id(value)
18
33
  end
19
34
  end
20
35
  end
@@ -2,7 +2,7 @@ module CompositePrimaryKeys
2
2
  module VERSION
3
3
  MAJOR = 12
4
4
  MINOR = 0
5
- TINY = 6
5
+ TINY = 7
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
  end
8
8
  end
@@ -1,7 +1,9 @@
1
1
  mysql:
2
2
  adapter: mysql2
3
- username: travis
4
- password: ""
3
+ username: github
4
+ password: github
5
+ host: 127.0.0.1
6
+ port: 3306
5
7
  encoding: utf8mb4
6
8
  charset: utf8mb4
7
9
  collation: utf8mb4_bin
@@ -11,6 +13,7 @@ postgresql:
11
13
  adapter: postgresql
12
14
  database: composite_primary_keys_unittest
13
15
  username: postgres
16
+ password: postgres
14
17
  host: localhost
15
18
 
16
19
  sqlite:
data/test/test_create.rb CHANGED
@@ -48,12 +48,21 @@ class TestCreate < ActiveSupport::TestCase
48
48
  end
49
49
  end
50
50
 
51
+ def test_create_with_array
52
+ date = Date.new(2027, 01, 27)
53
+ tariff = Tariff.create!(id: [10, date], amount: 27)
54
+ refute_nil(tariff)
55
+ assert_equal([10, date], tariff.id)
56
+ assert_equal(date, tariff.start_date)
57
+ assert_equal(27, tariff.amount)
58
+ end
59
+
51
60
  def test_create_with_partial_serial
52
61
  attributes = {:location_id => 100}
53
62
 
54
63
  # SQLite does not support an autoincrementing field in a composite key
55
64
  if Department.connection.class.name == "ActiveRecord::ConnectionAdapters::SQLite3Adapter"
56
- attributes[:id] = 100
65
+ attributes[:id] = 200
57
66
  end
58
67
 
59
68
  department = Department.new(attributes)
@@ -177,4 +186,21 @@ class TestCreate < ActiveSupport::TestCase
177
186
  suburb = Suburb.find_or_create_by!(:name => 'New Suburb', :city_id => 3, :suburb_id => 1)
178
187
  refute_nil(suburb)
179
188
  end
189
+
190
+ def test_cache
191
+ Suburb.cache do
192
+ # Suburb does not exist
193
+ suburb = Suburb.find_by(:city_id => 10, :suburb_id => 10)
194
+ assert_nil(suburb)
195
+
196
+ # Create it
197
+ suburb = Suburb.create!(:name => 'New Suburb', :city_id => 10, :suburb_id => 10)
198
+
199
+ # Should be able to find it
200
+ suburb = Suburb.find_by(:city_id => 10)
201
+ refute_nil(suburb)
202
+ refute_nil(suburb.city_id)
203
+ refute_nil(suburb.suburb_id)
204
+ end
205
+ end
180
206
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: composite_primary_keys
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.0.6
4
+ version: 12.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charlie Savage
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-04 00:00:00.000000000 Z
11
+ date: 2021-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: Composite key support for ActiveRecord
42
- email:
42
+ email:
43
43
  executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
@@ -201,7 +201,7 @@ homepage: https://github.com/composite-primary-keys/composite_primary_keys
201
201
  licenses:
202
202
  - MIT
203
203
  metadata: {}
204
- post_install_message:
204
+ post_install_message:
205
205
  rdoc_options: []
206
206
  require_paths:
207
207
  - lib
@@ -216,16 +216,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
216
  - !ruby/object:Gem::Version
217
217
  version: '0'
218
218
  requirements: []
219
- rubygems_version: 3.1.4
220
- signing_key:
219
+ rubygems_version: 3.2.8
220
+ signing_key:
221
221
  specification_version: 4
222
222
  summary: Composite key support for ActiveRecord
223
223
  test_files:
224
- - test/abstract_unit.rb
225
224
  - test/README_tests.rdoc
225
+ - test/abstract_unit.rb
226
226
  - test/test_associations.rb
227
- - test/test_attributes.rb
228
227
  - test/test_attribute_methods.rb
228
+ - test/test_attributes.rb
229
229
  - test/test_calculations.rb
230
230
  - test/test_callbacks.rb
231
231
  - test/test_composite_arrays.rb