upsert 2.2.0 → 2.2.1

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
  SHA1:
3
- metadata.gz: dfb6bea0fbe024f56a107ddb4db99ef247b5ebdb
4
- data.tar.gz: 6a3f979f4b136debf07b327073b2e774fdd60322
3
+ metadata.gz: d0268cf71d5cdccb6336100af2ab5269affbec4c
4
+ data.tar.gz: 889d7278a2b046ab5848c76cec79a94d1dfa4ec6
5
5
  SHA512:
6
- metadata.gz: 850b04b05fab5c9ec30b9c27253fe8b751beef9dbbc7718abdd6cfbe93d6054796361cde49543018dd3afaf1c59ffe0c8baca1f2874b58053a94726cbf444112
7
- data.tar.gz: 49db75e385e5d9cb3960e9f8d8927e8fa0657932e8422fe5ee7f77bcaf77a8dfc5b844b28c8a061953a285590b0c6ed9a1e8f87afb6c7c3ab1ba0d8dbdb8e312
6
+ metadata.gz: 60420f2b09bf34a80277104589cb7ef3cf376548c2f65fcef2a3bed6b11559b50e42bb4cbdf358d850f305b962dc421f4cb873da0fb5ab4b14c6edc372ef498c
7
+ data.tar.gz: b4cbb08f7546fb13eb5eb784eb85c7ed3ecd93008f9cc0be31e05c17cc74ac160d5ea36bd0b7f39bd800982d35eff9bfeee00357b027d74142459fd99e7ed099
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ 2.2.1 / 2017-04-20
2
+
3
+ * Bug fixes
4
+
5
+ * Fix unique constraint detection on pg >9.5.5 (@pnomolos https://github.com/seamusabshere/upsert/pull/99)
6
+ * Fix Ruby 1.9 tests
7
+
1
8
  2.2.0 / 2017-04-14
2
9
 
3
10
  * Enhancements
data/README.md CHANGED
@@ -23,7 +23,7 @@ You pass a __selector__ that uniquely identifies a row, whether it exists or not
23
23
  Syntax inspired by [mongo-ruby-driver's update method](http://api.mongodb.org/ruby/1.6.4/Mongo/Collection.html#update-instance_method).
24
24
 
25
25
  ### Basic
26
-
26
+
27
27
  ```ruby
28
28
  connection = Mysql2::Client.new([...])
29
29
  table_name = :pets
@@ -59,9 +59,11 @@ Batch mode is tested to be about 80% faster on PostgreSQL, MySQL, and SQLite3 th
59
59
 
60
60
  ### Native Postgres upsert
61
61
 
62
- `INSERT ... ON CONFLICT DO UPDATE` is used when Postgres 9.5+ is detected and *unique indexes are in place.*
62
+ `INSERT ... ON CONFLICT DO UPDATE` is used when Postgres 9.5+ is detected and *unique constraint are in place.*
63
+
64
+ **Note: ** You must have a **unique constraint** on the column(s) you're using as a selector. A unique index won't work. See https://github.com/seamusabshere/upsert/issues/98#issuecomment-295341405 for more information and some ways to check.
63
65
 
64
- If you don't have unique indexes, it will fall back to the classic Upsert gem user-defined function, which does not require indexes.
66
+ If you don't have unique constraints, it will fall back to the classic Upsert gem user-defined function, which does not require a constraint.
65
67
 
66
68
  ### ActiveRecord helper method
67
69
 
@@ -173,7 +175,7 @@ BEGIN
173
175
  DECLARE done BOOLEAN;
174
176
  REPEAT
175
177
  BEGIN
176
- -- If there is a unique key constraint error then
178
+ -- If there is a unique key constraint error then
177
179
  -- someone made a concurrent insert. Reset the sentinel
178
180
  -- and try again.
179
181
  DECLARE ER_DUP_UNIQUE CONDITION FOR 23000;
@@ -181,7 +183,7 @@ BEGIN
181
183
  DECLARE CONTINUE HANDLER FOR ER_DUP_UNIQUE BEGIN
182
184
  SET done = FALSE;
183
185
  END;
184
-
186
+
185
187
  DECLARE CONTINUE HANDLER FOR ER_INTEG BEGIN
186
188
  SET done = TRUE;
187
189
  END;
@@ -191,7 +193,7 @@ BEGIN
191
193
  -- Race condition here. If a concurrent INSERT is made after
192
194
  -- the SELECT but before the INSERT below we'll get a duplicate
193
195
  -- key error. But the handler above will take care of that.
194
- IF @count > 0 THEN
196
+ IF @count > 0 THEN
195
197
  -- UPDATE table_name SET b = b_SET WHERE a = a_SEL;
196
198
  UPDATE `pets` SET `name` = `name_set`, `tag_number` = `tag_number_set` WHERE `name` = `name_sel` AND `tag_number` = `tag_number_sel`;
197
199
  ELSE
@@ -15,9 +15,9 @@ class Upsert
15
15
  return @unique_index_on_selector if defined?(@unique_index_on_selector)
16
16
 
17
17
  type_map = PG::TypeMapByColumn.new([PG::TextDecoder::Array.new])
18
- schema_query.type_map = type_map
18
+ res = schema_query.tap { |r| r.type_map = type_map }
19
19
 
20
- @unique_index_on_selector = schema_query.values.any? do |row|
20
+ @unique_index_on_selector = res.values.any? do |row|
21
21
  row.first.sort == selector_keys.sort
22
22
  end
23
23
  end
@@ -1,3 +1,3 @@
1
1
  class Upsert
2
- VERSION = '2.2.0'
2
+ VERSION = '2.2.1'
3
3
  end
@@ -24,7 +24,6 @@ Gem::Specification.new do |gem|
24
24
 
25
25
  gem.add_development_dependency 'activerecord', '~>3'
26
26
  gem.add_development_dependency 'active_record_inline_schema'
27
- gem.add_development_dependency 'faker'
28
27
  gem.add_development_dependency 'yard'
29
28
  gem.add_development_dependency 'pry'
30
29
  gem.add_development_dependency 'pg-hstore', ">=1.1.3"
@@ -57,4 +56,10 @@ Gem::Specification.new do |gem|
57
56
  gem.add_development_dependency 'redcarpet', '~> 2.3.0'
58
57
  end
59
58
  end
59
+
60
+ if RUBY_VERSION <= '1.9.3'
61
+ gem.add_development_dependency 'faker', '1.6.3'
62
+ else
63
+ gem.add_development_dependency 'faker'
64
+ end
60
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upsert
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-04-14 00:00:00.000000000 Z
12
+ date: 2017-04-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec-core
@@ -81,20 +81,6 @@ dependencies:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
- - !ruby/object:Gem::Dependency
85
- name: faker
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: '0'
91
- type: :development
92
- prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- version: '0'
98
84
  - !ruby/object:Gem::Dependency
99
85
  name: yard
100
86
  requirement: !ruby/object:Gem::Requirement
@@ -249,6 +235,20 @@ dependencies:
249
235
  - - ">="
250
236
  - !ruby/object:Gem::Version
251
237
  version: '0'
238
+ - !ruby/object:Gem::Dependency
239
+ name: faker
240
+ requirement: !ruby/object:Gem::Requirement
241
+ requirements:
242
+ - - ">="
243
+ - !ruby/object:Gem::Version
244
+ version: '0'
245
+ type: :development
246
+ prerelease: false
247
+ version_requirements: !ruby/object:Gem::Requirement
248
+ requirements:
249
+ - - ">="
250
+ - !ruby/object:Gem::Version
251
+ version: '0'
252
252
  description: Make it easy to upsert on MySQL, PostgreSQL, and SQLite3. Transparently
253
253
  creates merge functions for MySQL and PostgreSQL; on SQLite3, uses INSERT OR IGNORE.
254
254
  email: