postgres_upsert 3.0.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.gitignore +1 -0
- data/.travis.yml +9 -0
- data/Gemfile.lock +93 -54
- data/README.md +106 -40
- data/Rakefile +4 -16
- data/bin/bundle +3 -0
- data/bin/rails +4 -0
- data/bin/rake +4 -0
- data/bin/setup +29 -0
- data/config.ru +4 -0
- data/config/application.rb +24 -0
- data/config/boot.rb +3 -0
- data/config/database.yml +22 -0
- data/config/environment.rb +5 -0
- data/config/environments/development.rb +41 -0
- data/config/environments/production.rb +79 -0
- data/config/environments/test.rb +42 -0
- data/config/locales/en.yml +23 -0
- data/config/routes.rb +56 -0
- data/config/secrets.yml +22 -0
- data/db/migrate/20150214192135_create_test_tables.rb +19 -0
- data/db/schema.rb +28 -0
- data/db/seeds.rb +7 -0
- data/lib/postgres_upsert.rb +8 -5
- data/lib/postgres_upsert/result.rb +11 -0
- data/lib/postgres_upsert/table_writer.rb +46 -0
- data/lib/postgres_upsert/writer.rb +25 -54
- data/postgres_upsert.gemspec +2 -2
- data/spec/pg_upsert_csv_spec.rb +87 -29
- data/spec/spec_helper.rb +5 -37
- metadata +42 -28
- data/lib/postgres_upsert/active_record.rb +0 -13
- data/spec/fixtures/2_col_binary_data.dat +0 -0
- data/spec/pg_upsert_binary_spec.rb +0 -35
- data/spec/spec.opts +0 -1
data/spec/spec_helper.rb
CHANGED
@@ -1,47 +1,15 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
require File.expand_path("../../config/environment", __FILE__)
|
2
3
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
4
|
require 'fixtures/test_model'
|
4
5
|
require 'fixtures/three_column'
|
5
6
|
require 'fixtures/reserved_word_model'
|
6
7
|
require 'rspec'
|
8
|
+
require 'rspec/rails'
|
7
9
|
require 'rspec/autorun'
|
8
10
|
|
9
11
|
RSpec.configure do |config|
|
10
|
-
config.
|
11
|
-
|
12
|
-
|
13
|
-
begin
|
14
|
-
ActiveRecord::Base.establish_connection(
|
15
|
-
:adapter => "postgresql",
|
16
|
-
:host => "localhost",
|
17
|
-
:username => "postgres",
|
18
|
-
:password => "postgres",
|
19
|
-
:port => 5432,
|
20
|
-
:database => "ar_pg_copy_test"
|
21
|
-
)
|
22
|
-
ActiveRecord::Base.connection.execute %{
|
23
|
-
SET client_min_messages TO warning;
|
24
|
-
DROP TABLE IF EXISTS test_models;
|
25
|
-
DROP TABLE IF EXISTS three_columns;
|
26
|
-
DROP TABLE IF EXISTS reserved_word_models;
|
27
|
-
CREATE TABLE test_models (id serial PRIMARY KEY, data text, created_at timestamp with time zone, updated_at timestamp with time zone );
|
28
|
-
CREATE TABLE three_columns (id serial PRIMARY KEY, data text, extra text, created_at timestamp with time zone, updated_at timestamp with time zone );
|
29
|
-
CREATE TABLE reserved_word_models (id serial PRIMARY KEY, "select" text, "group" text);
|
30
|
-
}
|
31
|
-
rescue Exception => e
|
32
|
-
puts "Exception: #{e}"
|
33
|
-
ActiveRecord::Base.establish_connection(
|
34
|
-
:adapter => "postgresql",
|
35
|
-
:host => "localhost",
|
36
|
-
:username => "postgres",
|
37
|
-
:password => "postgres",
|
38
|
-
:port => 5432,
|
39
|
-
:database => "postgres"
|
40
|
-
)
|
41
|
-
ActiveRecord::Base.connection.execute "DROP DATABASE IF EXISTS ar_pg_copy_test"
|
42
|
-
ActiveRecord::Base.connection.execute "CREATE DATABASE ar_pg_copy_test;"
|
43
|
-
retry
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
12
|
+
#config.use_transactional_fixtures = false
|
13
|
+
config.expose_current_running_example_as :example
|
14
|
+
config.infer_spec_type_from_file_location!
|
47
15
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postgres_upsert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Mitchell
|
@@ -28,86 +28,86 @@ dependencies:
|
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - '>='
|
31
|
+
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 3.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - '>='
|
38
|
+
- - ! '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 3.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - '>='
|
45
|
+
- - ! '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 3.0.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - '>='
|
52
|
+
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 3.0.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - '>='
|
59
|
+
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - '>='
|
66
|
+
- - ! '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: pry-rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - '>='
|
73
|
+
- - ! '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - '>='
|
80
|
+
- - ! '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ~>
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '2.12'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ~>
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '2.12'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name: rspec
|
98
|
+
name: rspec-rails
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ~>
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '2.
|
103
|
+
version: '2.0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - ~>
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '2.
|
110
|
+
version: '2.0'
|
111
111
|
description: Uses Postgres's powerful COPY command to upsert large sets of data into
|
112
112
|
ActiveRecord tables
|
113
113
|
email: thestevemitchell@gmail.com
|
@@ -116,17 +116,36 @@ extensions: []
|
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
118
|
- .gitignore
|
119
|
+
- .travis.yml
|
119
120
|
- Gemfile
|
120
121
|
- Gemfile.lock
|
121
122
|
- LICENSE
|
122
123
|
- README.md
|
123
124
|
- Rakefile
|
124
125
|
- VERSION
|
126
|
+
- bin/bundle
|
127
|
+
- bin/rails
|
128
|
+
- bin/rake
|
129
|
+
- bin/setup
|
130
|
+
- config.ru
|
131
|
+
- config/application.rb
|
132
|
+
- config/boot.rb
|
133
|
+
- config/database.yml
|
134
|
+
- config/environment.rb
|
135
|
+
- config/environments/development.rb
|
136
|
+
- config/environments/production.rb
|
137
|
+
- config/environments/test.rb
|
138
|
+
- config/locales/en.yml
|
139
|
+
- config/routes.rb
|
140
|
+
- config/secrets.yml
|
141
|
+
- db/migrate/20150214192135_create_test_tables.rb
|
142
|
+
- db/schema.rb
|
143
|
+
- db/seeds.rb
|
125
144
|
- lib/postgres_upsert.rb
|
126
|
-
- lib/postgres_upsert/
|
145
|
+
- lib/postgres_upsert/result.rb
|
146
|
+
- lib/postgres_upsert/table_writer.rb
|
127
147
|
- lib/postgres_upsert/writer.rb
|
128
148
|
- postgres_upsert.gemspec
|
129
|
-
- spec/fixtures/2_col_binary_data.dat
|
130
149
|
- spec/fixtures/comma_with_header.csv
|
131
150
|
- spec/fixtures/comma_with_header_and_comma_values.csv
|
132
151
|
- spec/fixtures/comma_with_header_and_unquoted_comma.csv
|
@@ -144,9 +163,7 @@ files:
|
|
144
163
|
- spec/fixtures/tab_with_two_lines.csv
|
145
164
|
- spec/fixtures/test_model.rb
|
146
165
|
- spec/fixtures/three_column.rb
|
147
|
-
- spec/pg_upsert_binary_spec.rb
|
148
166
|
- spec/pg_upsert_csv_spec.rb
|
149
|
-
- spec/spec.opts
|
150
167
|
- spec/spec_helper.rb
|
151
168
|
homepage: https://github.com/theSteveMitchell/postgres_upsert
|
152
169
|
licenses: []
|
@@ -157,23 +174,22 @@ require_paths:
|
|
157
174
|
- lib
|
158
175
|
required_ruby_version: !ruby/object:Gem::Requirement
|
159
176
|
requirements:
|
160
|
-
- - '>='
|
177
|
+
- - ! '>='
|
161
178
|
- !ruby/object:Gem::Version
|
162
179
|
version: 1.8.7
|
163
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
181
|
requirements:
|
165
|
-
- - '>='
|
182
|
+
- - ! '>='
|
166
183
|
- !ruby/object:Gem::Version
|
167
184
|
version: '0'
|
168
185
|
requirements: []
|
169
186
|
rubyforge_project:
|
170
|
-
rubygems_version: 2.
|
187
|
+
rubygems_version: 2.4.5
|
171
188
|
signing_key:
|
172
189
|
specification_version: 4
|
173
190
|
summary: A rubygem that integrates with ActiveRecord to insert/update large data sets
|
174
191
|
into the database efficiently
|
175
192
|
test_files:
|
176
|
-
- spec/fixtures/2_col_binary_data.dat
|
177
193
|
- spec/fixtures/comma_with_header.csv
|
178
194
|
- spec/fixtures/comma_with_header_and_comma_values.csv
|
179
195
|
- spec/fixtures/comma_with_header_and_unquoted_comma.csv
|
@@ -191,7 +207,5 @@ test_files:
|
|
191
207
|
- spec/fixtures/tab_with_two_lines.csv
|
192
208
|
- spec/fixtures/test_model.rb
|
193
209
|
- spec/fixtures/three_column.rb
|
194
|
-
- spec/pg_upsert_binary_spec.rb
|
195
210
|
- spec/pg_upsert_csv_spec.rb
|
196
|
-
- spec/spec.opts
|
197
211
|
- spec/spec_helper.rb
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
class Base
|
3
|
-
# Copy data to a file passed as a string (the file path) or to lines that are passed to a block
|
4
|
-
|
5
|
-
# Copy data from a CSV that can be passed as a string (the file path) or as an IO object.
|
6
|
-
# * You can change the default delimiter passing delimiter: '' in the options hash
|
7
|
-
# * You can map fields from the file to different fields in the table using a map in the options hash
|
8
|
-
# * For further details on usage take a look at the README.md
|
9
|
-
def self.pg_upsert path_or_io, options = {}
|
10
|
-
PostgresUpsert::Writer.new(table_name, path_or_io, options).write
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
Binary file
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe "pg_upsert from file with binary data" do
|
4
|
-
before(:each) do
|
5
|
-
ActiveRecord::Base.connection.execute %{
|
6
|
-
TRUNCATE TABLE test_models;
|
7
|
-
SELECT setval('test_models_id_seq', 1, false);
|
8
|
-
}
|
9
|
-
end
|
10
|
-
|
11
|
-
before do
|
12
|
-
DateTime.stub(:now).and_return (DateTime.parse("2012-01-01").utc)
|
13
|
-
end
|
14
|
-
|
15
|
-
def timestamp
|
16
|
-
DateTime.now.utc.to_s
|
17
|
-
end
|
18
|
-
|
19
|
-
it "imports from file if path is passed without field_map" do
|
20
|
-
TestModel.pg_upsert File.expand_path('spec/fixtures/2_col_binary_data.dat'), :format => :binary, columns: [:id, :data]
|
21
|
-
|
22
|
-
expect(
|
23
|
-
TestModel.first.attributes
|
24
|
-
).to include('data' => 'text', 'created_at' => timestamp, 'updated_at' => timestamp)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "throws an error when importing binary file without columns list" do
|
28
|
-
# Since binary data never has a header row, we'll require explicit columns list
|
29
|
-
expect{
|
30
|
-
TestModel.pg_upsert File.expand_path('spec/fixtures/2_col_binary_data.dat'), :format => :binary
|
31
|
-
}.to raise_error "Either the :columns option or :header => true are required"
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|