activerecord_upsert 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8cbd25aa6318ec5dd56d94342b23f35bb888de2e08a9ad775f3e36ec672a804b
4
- data.tar.gz: b19435c408f5ba2022b5a1e992cafb7920196e3705ccbcbf71f0a616699fcb11
3
+ metadata.gz: f720ddde1a95fa6611eb84c3a799c4cf64f9c72a2bbbb595f88f91fccda921e3
4
+ data.tar.gz: 4a360f14abccbdd55d0fdc77178c7c4d03e1f26d36126baacc1012866dfc38ef
5
5
  SHA512:
6
- metadata.gz: c136d6f7f5ca22d8d6d7ff98ae4a513b01e53c8b9b8323af6d6ab8013631e7334be5bba390547bf2efbcb8c60745e092a4eec933af5b3cfd34bfde08b1e16b4d
7
- data.tar.gz: 13839119ff4f61e426650cd1c4f25d892bdb852741a6b5cdbcb2f1a2743766be870b5aca4e7b4ab48daaa608b02003981459e9ddbcef46c76692bf1d764339c2
6
+ metadata.gz: b264d9f72178e27d6bc476fe5734452557bcbc609ab50c46ac23d097f86f88951b745828b90cd8455e54f3c44119090426b537bbf5425174d7ece3453e26abd6
7
+ data.tar.gz: b87c93ff47ff37470a966ae85b314a8319cb374a6a5889d7f8cf06376ebece93c28c768b55802fac3006abaecc5d388644bba891acb75f33fea0f587df935284
@@ -1,4 +1,5 @@
1
- sudo: false
1
+ os: linux
2
+
2
3
  language: ruby
3
4
  services:
4
5
  - mysql
@@ -11,15 +12,22 @@ rvm:
11
12
  - 2.4.9
12
13
  - 2.5.7
13
14
  - 2.6.5
14
- - 2.7.0.preview3
15
+ - 2.7.0
15
16
  gemfile:
16
- - Gemfile
17
- - .travis/gemfiles/Gemfile-no-cpk
17
+ - .travis/gemfiles/rails5.gemfile
18
+ - .travis/gemfiles/rails5-no-cpk.gemfile
19
+ - .travis/gemfiles/rails6.gemfile
20
+ - .travis/gemfiles/rails6-no-cpk.gemfile
18
21
  before_install:
19
22
  - gem install bundler -v 2.0.2
20
23
  - mysql -e 'CREATE DATABASE active_record_upsert_test;'
21
24
  matrix:
22
- allow_failures:
23
- - rvm: 2.7.0.preview3
24
-
25
-
25
+ exclude:
26
+ - rvm: 2.3.8
27
+ gemfile: .travis/gemfiles/rails6.gemfile
28
+ - rvm: 2.3.8
29
+ gemfile: .travis/gemfiles/rails6-no-cpk.gemfile
30
+ - rvm: 2.4.9
31
+ gemfile: .travis/gemfiles/rails6.gemfile
32
+ - rvm: 2.4.9
33
+ gemfile: .travis/gemfiles/rails6-no-cpk.gemfile
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in activerecord_upsert.gemspec
4
4
  gemspec path: '../..'
5
+
6
+ gem 'activerecord', '~> 5.2.4.1'
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activerecord_upsert.gemspec
4
+ gemspec path: '../..'
5
+
6
+ gem 'activerecord', '~> 5.2.4.1'
7
+ gem 'composite_primary_keys', '~> 11.2'
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activerecord_upsert.gemspec
4
+ gemspec path: '../..'
5
+
6
+ gem 'activerecord', '~> 6.0.2.1'
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activerecord_upsert.gemspec
4
+ gemspec path: '../..'
5
+
6
+ gem 'activerecord', '~> 6.0.2.1'
7
+ gem 'composite_primary_keys', '~> 12.0'
@@ -1,5 +1,8 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v0.3.0 (March 18, 2019)
4
+ - Added support for Rails 6.
5
+
3
6
  ## v0.2.0 (December 16, 2019)
4
7
  - Added compatibility with `composite_primary_keys` gem.
5
8
 
data/Gemfile CHANGED
@@ -3,4 +3,5 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in activerecord_upsert.gemspec
4
4
  gemspec
5
5
 
6
- gem 'composite_primary_keys', '~> 11.2'
6
+ gem 'activerecord', '~> 6.0.2.1'
7
+ gem 'composite_primary_keys', '~> 12.0'
data/README.md CHANGED
@@ -3,9 +3,9 @@
3
3
  [![Build Status](https://travis-ci.org/dvandersluis/activerecord_upsert.svg?branch=master)](https://travis-ci.org/dvandersluis/activerecord_upsert)
4
4
  [![Gem Version](https://badge.fury.io/rb/activerecord_upsert.svg)](https://badge.fury.io/rb/activerecord_upsert)
5
5
 
6
- Adds the ability to use MySQL's `ON DUPLICATE KEY UPDATE` to upsert records in ActiveRecord.
6
+ Adds the ability to use MySQL's `ON DUPLICATE KEY UPDATE` with arbitrary values in order to upsert records in ActiveRecord.
7
7
 
8
- **Note**: This will conflict with Rails 6, which adds its own upsert, so requires Rails 5.2 currently.
8
+ Supports Rails 5.2 and 6, and should not conflict with Rails 6's `Model.upsert` or `Model.upsert_all`, because this gem adds `upsert` to `ActiveRecord::Relation`.
9
9
 
10
10
  ## Installation
11
11
 
@@ -29,12 +29,12 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ['lib']
30
30
 
31
31
  spec.add_dependency 'mysql2'
32
- spec.add_dependency 'activerecord', '>= 5.2', '< 6'
32
+ spec.add_dependency 'activerecord', '>= 5.2', '< 7'
33
33
 
34
34
  spec.add_development_dependency('bundler', '~> 2.0')
35
35
  spec.add_development_dependency('database_cleaner', '~> 1.7.0')
36
36
  spec.add_development_dependency('pry', '~> 0.12.0')
37
- spec.add_development_dependency('rake', '~> 10.0')
37
+ spec.add_development_dependency('rake', '>= 12.3.3')
38
38
  spec.add_development_dependency('rspec', '~> 3.0')
39
39
  spec.add_development_dependency('rubocop', '~> 0.75.0')
40
40
  spec.add_development_dependency('rubocop-rspec', '~> 1.36.0')
@@ -6,16 +6,10 @@ require 'active_record'
6
6
  require 'active_record_upsert/arel/insert_manager'
7
7
  require 'active_record_upsert/arel/insert_statement'
8
8
  require 'active_record_upsert/arel/visitors/mysql'
9
-
10
- require 'active_record_upsert/active_record/persistence'
11
- require 'active_record_upsert/active_record/relation'
12
-
13
- module ActiveRecordUpsert
14
- end
9
+ require 'active_record_upsert/active_record'
15
10
 
16
11
  Arel::Nodes::InsertStatement.include ActiveRecordUpsert::Arel::InsertStatement
17
12
  Arel::InsertManager.include ActiveRecordUpsert::Arel::InsertManager
18
13
  Arel::Visitors::MySQL.prepend ActiveRecordUpsert::Arel::Visitors::MySQL
19
14
 
20
- ActiveRecord::Relation.include ActiveRecordUpsert::ActiveRecord::Relation
21
- ActiveRecord::Persistence::ClassMethods.include ActiveRecordUpsert::ActiveRecord::Persistence
15
+ ActiveRecord::Base.include ActiveRecordUpsert::ActiveRecord
@@ -0,0 +1,18 @@
1
+ module ActiveRecordUpsert
2
+ module ActiveRecord
3
+ def self.included(*)
4
+ require 'active_record_upsert/active_record/persistence'
5
+ ::ActiveRecord::Base.extend ActiveRecordUpsert::ActiveRecord::Persistence
6
+
7
+ if ::ActiveRecord::VERSION::MAJOR == 5
8
+ require 'active_record_upsert/active_record5/relation'
9
+
10
+ ::ActiveRecord::Relation.include ActiveRecordUpsert::ActiveRecord5::Relation
11
+ elsif ::ActiveRecord::VERSION::MAJOR == 6
12
+ require 'active_record_upsert/active_record6/relation'
13
+
14
+ ::ActiveRecord::Relation.include ActiveRecordUpsert::ActiveRecord6::Relation
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecordUpsert
2
- module ActiveRecord
2
+ module ActiveRecord5
3
3
  module Relation
4
4
  def upsert(on_duplicate = nil)
5
5
  scoping { klass._upsert_record(values_for_create, on_duplicate) }
@@ -0,0 +1,15 @@
1
+ module ActiveRecordUpsert
2
+ module ActiveRecord6
3
+ module Relation
4
+ def upsert(on_duplicate = nil)
5
+ scoping { klass._upsert_record(values_for_create, on_duplicate) }
6
+ end
7
+
8
+ private
9
+
10
+ def values_for_create
11
+ klass.current_scope.values[:where].to_h
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordUpsert
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_upsert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Vandersluis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-16 00:00:00.000000000 Z
11
+ date: 2020-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '5.2'
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: '6'
36
+ version: '7'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '5.2'
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: '6'
46
+ version: '7'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -90,16 +90,16 @@ dependencies:
90
90
  name: rake
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - "~>"
93
+ - - ">="
94
94
  - !ruby/object:Gem::Version
95
- version: '10.0'
95
+ version: 12.3.3
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - "~>"
100
+ - - ">="
101
101
  - !ruby/object:Gem::Version
102
- version: '10.0'
102
+ version: 12.3.3
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: rspec
105
105
  requirement: !ruby/object:Gem::Requirement
@@ -167,7 +167,10 @@ files:
167
167
  - ".rspec"
168
168
  - ".rubocop.yml"
169
169
  - ".travis.yml"
170
- - ".travis/gemfiles/Gemfile-no-cpk"
170
+ - ".travis/gemfiles/rails5-no-cpk.gemfile"
171
+ - ".travis/gemfiles/rails5.gemfile"
172
+ - ".travis/gemfiles/rails6-no-cpk.gemfile"
173
+ - ".travis/gemfiles/rails6.gemfile"
171
174
  - CHANGELOG.md
172
175
  - Gemfile
173
176
  - README.md
@@ -176,8 +179,10 @@ files:
176
179
  - bin/console
177
180
  - bin/setup
178
181
  - lib/active_record_upsert.rb
182
+ - lib/active_record_upsert/active_record.rb
179
183
  - lib/active_record_upsert/active_record/persistence.rb
180
- - lib/active_record_upsert/active_record/relation.rb
184
+ - lib/active_record_upsert/active_record5/relation.rb
185
+ - lib/active_record_upsert/active_record6/relation.rb
181
186
  - lib/active_record_upsert/arel/insert_manager.rb
182
187
  - lib/active_record_upsert/arel/insert_statement.rb
183
188
  - lib/active_record_upsert/arel/visitors/mysql.rb