postgres_upsert 5.0.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.rubocop.yml +57 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +18 -3
- data/Gemfile +1 -2
- data/Gemfile.lock +171 -109
- data/README.md +8 -5
- data/app/assets/config/manifest.js +0 -0
- data/bin/setup +27 -0
- data/config/application.rb +0 -3
- data/config/database.yml +2 -0
- data/config/database.yml.travis +23 -0
- data/db/migrate/20150214192135_create_test_tables.rb +6 -1
- data/db/migrate/20150710162236_create_composite_models_table.rb +1 -1
- data/db/schema.rb +22 -17
- data/lib/postgres_upsert.rb +35 -6
- data/lib/postgres_upsert/model_to_model_adapter.rb +37 -0
- data/lib/postgres_upsert/read_adapters/active_record_adapter.rb +37 -0
- data/lib/postgres_upsert/read_adapters/file_adapter.rb +42 -0
- data/lib/postgres_upsert/read_adapters/io_adapter.rb +42 -0
- data/lib/postgres_upsert/result.rb +3 -4
- data/lib/postgres_upsert/table_writer.rb +7 -9
- data/lib/postgres_upsert/write_adapters/active_record_adapter.rb +36 -0
- data/lib/postgres_upsert/write_adapters/table_adapter.rb +56 -0
- data/lib/postgres_upsert/writer.rb +87 -69
- data/postgres_upsert.gemspec +6 -3
- data/spec/composite_key_spec.rb +0 -6
- data/spec/fixtures/comma_with_header_duplicate.csv +3 -0
- data/spec/fixtures/test_model_copy.rb +4 -0
- data/spec/from_table_spec.rb +40 -0
- data/spec/pg_upsert_csv_spec.rb +11 -10
- data/spec/rails_helper.rb +1 -0
- data/spec/spec_helper.rb +5 -2
- metadata +77 -31
- data/VERSION +0 -1
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MjEwODZlMTFlOGIwNTk2NGE3Y2FjMThhYjM0ZDU1YTZkOTAzOWFlMA==
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 89478e281fa4cd37be98385dab13c96de8f4128702e4a9cfd1c7f8049d912fb8
|
4
|
+
data.tar.gz: b20dc2e32478209af409f86299ea5c702be7c7ec8cf87d7e2dd2035afe27130a
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NDY3ZmQwNjRiNjE0YjE0ZDgyYzU0N2Q1NzhhZTcxNjRmZThiNjUyZTJkMTkw
|
11
|
-
NjY0NDI2ODU1OWYyNjA3ZmVlY2EwODRiMzBmYTNhYzQxODQ2ODk=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZGIyNzNiZGUxOTNmZDVlNTQxMWRkNjk4OWYxZWUyNTQ2OTkzNGZlYzBjOGVj
|
14
|
-
NmY2NDNlZmZmNWYzZTEwZTEwZWEzMjAyYzE3ZGQyNjUyY2NjY2Q4NGFjODgw
|
15
|
-
MzY1ZjZlNjUwZjU4MmY3NDMwOGViMDhlNjJmZThhN2MyNjg3NGY=
|
6
|
+
metadata.gz: 4349cbfbeeeeb5bdd4b95086f693e19968319f9a3b4a2bf0dbb290789b9e9893496463a08335dd2e6f9f2d7c0717036cdabfdbca00e1d2ab394beb143bbd2d45
|
7
|
+
data.tar.gz: 8abcd0a2167f3ed42ed6fa1c70c145203a565a8a1418ea3f265a1b81a8267e22aa321b544d350d8c711d420d53c0263c9487bfc8678e5499dad1363475ee2cd0
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- '.*'
|
4
|
+
- 'app/*'
|
5
|
+
- 'bin/*'
|
6
|
+
- 'config*'
|
7
|
+
- 'db/*'
|
8
|
+
- '*.md'
|
9
|
+
- 'Gemfile'
|
10
|
+
- 'Gemfile.lock'
|
11
|
+
|
12
|
+
Layout/Tab:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Layout/IndentationWidth:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Metrics/LineLength:
|
19
|
+
Max: 99
|
20
|
+
|
21
|
+
Metrics/MethodLength:
|
22
|
+
CountAsOne: ['array', 'hash', 'heredoc']
|
23
|
+
|
24
|
+
Style/RescueModifier:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Layout/TrailingEmptyLines:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
Layout/AccessModifierIndentation:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
Style/BlockComments:
|
34
|
+
Exclude:
|
35
|
+
- 'spec/spec_helper.rb'
|
36
|
+
|
37
|
+
Style/Documentation:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Style/FrozenStringLiteralComment:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Style/HashEachMethods:
|
44
|
+
Enabled: true
|
45
|
+
|
46
|
+
Style/HashTransformKeys:
|
47
|
+
Enabled: true
|
48
|
+
|
49
|
+
Style/HashTransformValues:
|
50
|
+
Enabled: true
|
51
|
+
|
52
|
+
Metrics/BlockLength:
|
53
|
+
Exclude:
|
54
|
+
- 'spec/*'
|
55
|
+
|
56
|
+
Layout/MultilineMethodCallIndentation:
|
57
|
+
Enabled: false
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
postgres_upsert
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.5
|
data/.travis.yml
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
language: ruby
|
2
|
+
dist: trusty
|
3
|
+
before_install:
|
4
|
+
- gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
|
5
|
+
- gem install bundler
|
6
|
+
- cp config/database.yml.travis config/database.yml
|
7
|
+
- psql -c 'create database ar_pg_copy_test;' -U postgres
|
8
|
+
|
2
9
|
rvm:
|
3
|
-
- 2.
|
4
|
-
|
5
|
-
|
10
|
+
- 2.5.0
|
11
|
+
|
12
|
+
script:
|
13
|
+
- gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
|
14
|
+
- bundle exec rake db:setup
|
15
|
+
- bundle exec rspec spec
|
16
|
+
services:
|
17
|
+
postgresql
|
18
|
+
addons:
|
19
|
+
postgresql: "9.4"
|
20
|
+
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
postgres_upsert (5.
|
4
|
+
postgres_upsert (5.1.0)
|
5
5
|
activerecord (>= 3.0.0)
|
6
6
|
pg (>= 0.17.0)
|
7
7
|
rails (>= 3.0.0)
|
@@ -9,132 +9,194 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
|
13
|
-
actionpack (=
|
14
|
-
|
15
|
-
|
12
|
+
actioncable (6.1.3.2)
|
13
|
+
actionpack (= 6.1.3.2)
|
14
|
+
activesupport (= 6.1.3.2)
|
15
|
+
nio4r (~> 2.0)
|
16
|
+
websocket-driver (>= 0.6.1)
|
17
|
+
actionmailbox (6.1.3.2)
|
18
|
+
actionpack (= 6.1.3.2)
|
19
|
+
activejob (= 6.1.3.2)
|
20
|
+
activerecord (= 6.1.3.2)
|
21
|
+
activestorage (= 6.1.3.2)
|
22
|
+
activesupport (= 6.1.3.2)
|
23
|
+
mail (>= 2.7.1)
|
24
|
+
actionmailer (6.1.3.2)
|
25
|
+
actionpack (= 6.1.3.2)
|
26
|
+
actionview (= 6.1.3.2)
|
27
|
+
activejob (= 6.1.3.2)
|
28
|
+
activesupport (= 6.1.3.2)
|
16
29
|
mail (~> 2.5, >= 2.5.4)
|
17
|
-
rails-dom-testing (~>
|
18
|
-
actionpack (
|
19
|
-
actionview (=
|
20
|
-
activesupport (=
|
21
|
-
rack (~>
|
22
|
-
rack-test (
|
23
|
-
rails-dom-testing (~>
|
24
|
-
rails-html-sanitizer (~> 1.0, >= 1.0
|
25
|
-
|
26
|
-
|
30
|
+
rails-dom-testing (~> 2.0)
|
31
|
+
actionpack (6.1.3.2)
|
32
|
+
actionview (= 6.1.3.2)
|
33
|
+
activesupport (= 6.1.3.2)
|
34
|
+
rack (~> 2.0, >= 2.0.9)
|
35
|
+
rack-test (>= 0.6.3)
|
36
|
+
rails-dom-testing (~> 2.0)
|
37
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
38
|
+
actiontext (6.1.3.2)
|
39
|
+
actionpack (= 6.1.3.2)
|
40
|
+
activerecord (= 6.1.3.2)
|
41
|
+
activestorage (= 6.1.3.2)
|
42
|
+
activesupport (= 6.1.3.2)
|
43
|
+
nokogiri (>= 1.8.5)
|
44
|
+
actionview (6.1.3.2)
|
45
|
+
activesupport (= 6.1.3.2)
|
27
46
|
builder (~> 3.1)
|
28
|
-
|
29
|
-
rails-dom-testing (~>
|
30
|
-
rails-html-sanitizer (~> 1.
|
31
|
-
activejob (
|
32
|
-
activesupport (=
|
33
|
-
globalid (>= 0.3.
|
34
|
-
activemodel (
|
35
|
-
activesupport (=
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
erubi (~> 1.4)
|
48
|
+
rails-dom-testing (~> 2.0)
|
49
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
50
|
+
activejob (6.1.3.2)
|
51
|
+
activesupport (= 6.1.3.2)
|
52
|
+
globalid (>= 0.3.6)
|
53
|
+
activemodel (6.1.3.2)
|
54
|
+
activesupport (= 6.1.3.2)
|
55
|
+
activerecord (6.1.3.2)
|
56
|
+
activemodel (= 6.1.3.2)
|
57
|
+
activesupport (= 6.1.3.2)
|
58
|
+
activestorage (6.1.3.2)
|
59
|
+
actionpack (= 6.1.3.2)
|
60
|
+
activejob (= 6.1.3.2)
|
61
|
+
activerecord (= 6.1.3.2)
|
62
|
+
activesupport (= 6.1.3.2)
|
63
|
+
marcel (~> 1.0.0)
|
64
|
+
mini_mime (~> 1.0.2)
|
65
|
+
activesupport (6.1.3.2)
|
66
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
67
|
+
i18n (>= 1.6, < 2)
|
68
|
+
minitest (>= 5.1)
|
69
|
+
tzinfo (~> 2.0)
|
70
|
+
zeitwerk (~> 2.3)
|
71
|
+
ast (2.4.1)
|
72
|
+
builder (3.2.4)
|
49
73
|
coderay (1.1.0)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
74
|
+
concurrent-ruby (1.1.8)
|
75
|
+
crass (1.0.6)
|
76
|
+
database_cleaner-active_record (2.0.1)
|
77
|
+
activerecord (>= 5.a)
|
78
|
+
database_cleaner-core (~> 2.0.0)
|
79
|
+
database_cleaner-core (2.0.1)
|
80
|
+
diff-lcs (1.4.4)
|
81
|
+
erubi (1.10.0)
|
82
|
+
globalid (0.4.2)
|
83
|
+
activesupport (>= 4.2.0)
|
84
|
+
i18n (1.8.10)
|
85
|
+
concurrent-ruby (~> 1.0)
|
86
|
+
jaro_winkler (1.5.4)
|
87
|
+
loofah (2.9.1)
|
88
|
+
crass (~> 1.0.2)
|
57
89
|
nokogiri (>= 1.5.9)
|
58
|
-
mail (2.
|
59
|
-
|
90
|
+
mail (2.7.1)
|
91
|
+
mini_mime (>= 0.1.1)
|
92
|
+
marcel (1.0.1)
|
60
93
|
method_source (0.8.2)
|
61
|
-
|
62
|
-
|
63
|
-
minitest (5.
|
64
|
-
|
65
|
-
|
66
|
-
|
94
|
+
mini_mime (1.0.3)
|
95
|
+
mini_portile2 (2.5.1)
|
96
|
+
minitest (5.14.4)
|
97
|
+
nio4r (2.5.7)
|
98
|
+
nokogiri (1.11.3)
|
99
|
+
mini_portile2 (~> 2.5.0)
|
100
|
+
racc (~> 1.4)
|
101
|
+
parallel (1.19.2)
|
102
|
+
parser (2.7.1.3)
|
103
|
+
ast (~> 2.4.0)
|
104
|
+
pg (1.2.3)
|
67
105
|
pry (0.10.1)
|
68
106
|
coderay (~> 1.1.0)
|
69
107
|
method_source (~> 0.8.1)
|
70
108
|
slop (~> 3.4)
|
109
|
+
pry-nav (0.3.0)
|
110
|
+
pry (>= 0.9.10, < 0.13.0)
|
71
111
|
pry-rails (0.3.2)
|
72
112
|
pry (>= 0.9.10)
|
73
|
-
|
74
|
-
rack
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
activesupport (
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
113
|
+
racc (1.5.2)
|
114
|
+
rack (2.2.3)
|
115
|
+
rack-test (1.1.0)
|
116
|
+
rack (>= 1.0, < 3)
|
117
|
+
rails (6.1.3.2)
|
118
|
+
actioncable (= 6.1.3.2)
|
119
|
+
actionmailbox (= 6.1.3.2)
|
120
|
+
actionmailer (= 6.1.3.2)
|
121
|
+
actionpack (= 6.1.3.2)
|
122
|
+
actiontext (= 6.1.3.2)
|
123
|
+
actionview (= 6.1.3.2)
|
124
|
+
activejob (= 6.1.3.2)
|
125
|
+
activemodel (= 6.1.3.2)
|
126
|
+
activerecord (= 6.1.3.2)
|
127
|
+
activestorage (= 6.1.3.2)
|
128
|
+
activesupport (= 6.1.3.2)
|
129
|
+
bundler (>= 1.15.0)
|
130
|
+
railties (= 6.1.3.2)
|
131
|
+
sprockets-rails (>= 2.0.0)
|
132
|
+
rails-dom-testing (2.0.3)
|
133
|
+
activesupport (>= 4.2.0)
|
134
|
+
nokogiri (>= 1.6)
|
135
|
+
rails-html-sanitizer (1.3.0)
|
136
|
+
loofah (~> 2.3)
|
137
|
+
railties (6.1.3.2)
|
138
|
+
actionpack (= 6.1.3.2)
|
139
|
+
activesupport (= 6.1.3.2)
|
140
|
+
method_source
|
98
141
|
rake (>= 0.8.7)
|
99
|
-
thor (
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
rspec-
|
105
|
-
rspec-
|
106
|
-
|
107
|
-
|
108
|
-
rspec-
|
109
|
-
diff-lcs (>= 1.
|
110
|
-
|
111
|
-
rspec-rails (
|
112
|
-
actionpack (>=
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
rspec-
|
117
|
-
rspec-
|
118
|
-
rspec-
|
119
|
-
|
142
|
+
thor (~> 1.0)
|
143
|
+
rainbow (3.0.0)
|
144
|
+
rake (13.0.3)
|
145
|
+
rexml (3.2.4)
|
146
|
+
rspec-core (3.10.1)
|
147
|
+
rspec-support (~> 3.10.0)
|
148
|
+
rspec-expectations (3.10.1)
|
149
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
150
|
+
rspec-support (~> 3.10.0)
|
151
|
+
rspec-mocks (3.10.2)
|
152
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
153
|
+
rspec-support (~> 3.10.0)
|
154
|
+
rspec-rails (5.0.1)
|
155
|
+
actionpack (>= 5.2)
|
156
|
+
activesupport (>= 5.2)
|
157
|
+
railties (>= 5.2)
|
158
|
+
rspec-core (~> 3.10)
|
159
|
+
rspec-expectations (~> 3.10)
|
160
|
+
rspec-mocks (~> 3.10)
|
161
|
+
rspec-support (~> 3.10)
|
162
|
+
rspec-support (3.10.2)
|
163
|
+
rubocop (0.80.1)
|
164
|
+
jaro_winkler (~> 1.5.1)
|
165
|
+
parallel (~> 1.10)
|
166
|
+
parser (>= 2.7.0.1)
|
167
|
+
rainbow (>= 2.2.2, < 4.0)
|
168
|
+
rexml
|
169
|
+
ruby-progressbar (~> 1.7)
|
170
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
171
|
+
ruby-progressbar (1.10.1)
|
120
172
|
slop (3.6.0)
|
121
|
-
sprockets (
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
tzinfo (
|
130
|
-
|
173
|
+
sprockets (4.0.2)
|
174
|
+
concurrent-ruby (~> 1.0)
|
175
|
+
rack (> 1, < 3)
|
176
|
+
sprockets-rails (3.2.2)
|
177
|
+
actionpack (>= 4.0)
|
178
|
+
activesupport (>= 4.0)
|
179
|
+
sprockets (>= 3.0.0)
|
180
|
+
thor (1.1.0)
|
181
|
+
tzinfo (2.0.4)
|
182
|
+
concurrent-ruby (~> 1.0)
|
183
|
+
unicode-display_width (1.6.1)
|
184
|
+
websocket-driver (0.7.3)
|
185
|
+
websocket-extensions (>= 0.1.0)
|
186
|
+
websocket-extensions (0.1.5)
|
187
|
+
zeitwerk (2.4.2)
|
131
188
|
|
132
189
|
PLATFORMS
|
133
190
|
ruby
|
134
191
|
|
135
192
|
DEPENDENCIES
|
136
193
|
bundler
|
194
|
+
database_cleaner-active_record
|
137
195
|
postgres_upsert!
|
196
|
+
pry-nav
|
138
197
|
pry-rails
|
139
|
-
rspec (
|
140
|
-
|
198
|
+
rspec-rails (>= 3.9)
|
199
|
+
rubocop
|
200
|
+
|
201
|
+
BUNDLED WITH
|
202
|
+
2.2.3
|
data/README.md
CHANGED
@@ -113,7 +113,7 @@ And the following railsy code to create 10,000 users:
|
|
113
113
|
def insert_dumb
|
114
114
|
time = Benchmark.measure do
|
115
115
|
(1..10000).each do |n|
|
116
|
-
User.create!(:email => "number#{n}@
|
116
|
+
User.create!(:email => "number#{n}@email.com", :password => "password#{n)}")
|
117
117
|
end
|
118
118
|
end
|
119
119
|
puts time
|
@@ -125,9 +125,9 @@ Compared to the following code using Postgres_upsert:
|
|
125
125
|
def insert_smart
|
126
126
|
time = Benchmark.measure do
|
127
127
|
csv_string = CSV.generate do |csv|
|
128
|
-
csv << %w(email password)
|
128
|
+
csv << %w(email password) # CSV header row
|
129
129
|
(1..10000).each do |n|
|
130
|
-
csv << ["number#{n}@
|
130
|
+
csv << ["number#{n}@email.com", "password#{n)}"]
|
131
131
|
end
|
132
132
|
end
|
133
133
|
io = StringIO.new(csv_string)
|
@@ -158,8 +158,11 @@ Note that for the benchmark, my database is local. The performance improvement
|
|
158
158
|
|
159
159
|
## Note on Patches/Pull Requests
|
160
160
|
|
161
|
-
|
162
|
-
|
161
|
+
I greatly appreciate contribution to this gem.
|
162
|
+
|
163
|
+
* Fork the project and clone the repo locally
|
164
|
+
* run 'bin/setup' to setup dependencies and create test DB
|
165
|
+
* add your feature/fix to your fork(add and run rpsec tests please)
|
163
166
|
* submit a PR
|
164
167
|
* If you find an issue but can't fix in in a PR, please log an issue. I'll do my best.
|
165
168
|
|