cartodb-importer 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -111,6 +111,7 @@ module CartoDB
111
111
  end
112
112
 
113
113
  if @ext == '.csv'
114
+
114
115
  ogr2ogr_bin_path = `which ogr2ogr`.strip
115
116
  ogr2ogr_command = %Q{#{ogr2ogr_bin_path} -f "PostgreSQL" PG:"host=#{@db_configuration[:host]} port=#{@db_configuration[:port]} user=#{@db_configuration[:username]} dbname=#{@db_configuration[:database]}" #{path} -nln #{@suggested_name}}
116
117
 
@@ -322,17 +323,14 @@ module CartoDB
322
323
  end
323
324
 
324
325
  def get_valid_name(name)
325
- candidates = @db_connection.tables.map{ |t| t.to_s }.select{ |t| t.match(/^#{name}/) }
326
- if candidates.any?
327
- max_candidate = candidates.max
328
- if max_candidate =~ /(.+)_(\d+)$/
329
- return $1 + "_#{$2.to_i + 1}"
330
- else
331
- return max_candidate + "_2"
332
- end
333
- else
334
- return name
326
+ existing_names = @db_connection["select relname from pg_stat_user_tables WHERE schemaname='public' and relname ilike '#{name}%'"].map(:relname)
327
+ testn = 1
328
+ uniname = name
329
+ while true==existing_names.include?("#{uniname}")
330
+ uniname = "#{name}_#{testn}"
331
+ testn = testn + 1
335
332
  end
333
+ return uniname
336
334
  end
337
335
 
338
336
  def log(str)
@@ -1,6 +1,6 @@
1
1
  module CartoDB
2
2
  class Importer
3
- VERSION = "0.2.7"
3
+ VERSION = "0.2.8"
4
4
  end
5
5
  end
6
6
 
data/spec/import_spec.rb CHANGED
@@ -177,11 +177,19 @@ describe CartoDB::Importer do
177
177
  it "should import estaciones2.csv" do
178
178
  importer = CartoDB::Importer.new :import_from_file => File.expand_path("../support/data/estaciones2.csv", __FILE__),
179
179
  :database => "cartodb_importer_test", :username => 'postgres', :password => '',
180
- :host => 'localhost', :port => 5432
180
+ :host => 'localhost', :port => 5432, :suggested_name => 'estaciones2'
181
181
  result = importer.import!
182
182
  result.name.should == 'estaciones2'
183
183
  result.rows_imported.should == 30
184
184
  result.import_type.should == '.csv'
185
+
186
+ importer2 = CartoDB::Importer.new :import_from_file => File.expand_path("../support/data/estaciones2.csv", __FILE__),
187
+ :database => "cartodb_importer_test", :username => 'postgres', :password => '',
188
+ :host => 'localhost', :port => 5432, :suggested_name => 'estaciones2'
189
+ result2 = importer2.import!
190
+ result2.name.should == 'estaciones2_0'
191
+ result2.rows_imported.should == 30
192
+ result2.import_type.should == '.csv'
185
193
  end
186
194
  end
187
195
 
@@ -263,7 +271,7 @@ describe CartoDB::Importer do
263
271
  :database => "cartodb_importer_test", :username => 'postgres', :password => '',
264
272
  :host => 'localhost', :port => 5432
265
273
  result2 = importer.import!
266
- result2.name.should == 'tm_world_borders_simpl_0_4'
274
+ result2.name.should == 'tm_world_borders_simpl_0_3_0'
267
275
  #result.rows_imported.should == 4365
268
276
  result2.import_type.should == '.shp'
269
277
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cartodb-importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-09-13 00:00:00.000000000Z
14
+ date: 2011-09-14 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: pg
18
- requirement: &70204688871100 !ruby/object:Gem::Requirement
18
+ requirement: &70263347758260 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '0.11'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70204688871100
26
+ version_requirements: *70263347758260
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sequel
29
- requirement: &70204688870460 !ruby/object:Gem::Requirement
29
+ requirement: &70263347757840 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: '0'
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *70204688870460
37
+ version_requirements: *70263347757840
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: roo
40
- requirement: &70204688869740 !ruby/object:Gem::Requirement
40
+ requirement: &70263347757380 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: '0'
46
46
  type: :runtime
47
47
  prerelease: false
48
- version_requirements: *70204688869740
48
+ version_requirements: *70263347757380
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: spreadsheet
51
- requirement: &70204688869160 !ruby/object:Gem::Requirement
51
+ requirement: &70263347756940 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ! '>='
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: '0'
57
57
  type: :runtime
58
58
  prerelease: false
59
- version_requirements: *70204688869160
59
+ version_requirements: *70263347756940
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: google-spreadsheet-ruby
62
- requirement: &70204688868520 !ruby/object:Gem::Requirement
62
+ requirement: &70263347756360 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ! '>='
@@ -67,10 +67,10 @@ dependencies:
67
67
  version: '0'
68
68
  type: :runtime
69
69
  prerelease: false
70
- version_requirements: *70204688868520
70
+ version_requirements: *70263347756360
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rubyzip
73
- requirement: &70204688867880 !ruby/object:Gem::Requirement
73
+ requirement: &70263347755840 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ! '>='
@@ -78,10 +78,10 @@ dependencies:
78
78
  version: '0'
79
79
  type: :runtime
80
80
  prerelease: false
81
- version_requirements: *70204688867880
81
+ version_requirements: *70263347755840
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: builder
84
- requirement: &70204688867260 !ruby/object:Gem::Requirement
84
+ requirement: &70263347755180 !ruby/object:Gem::Requirement
85
85
  none: false
86
86
  requirements:
87
87
  - - ! '>='
@@ -89,10 +89,10 @@ dependencies:
89
89
  version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
- version_requirements: *70204688867260
92
+ version_requirements: *70263347755180
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: rspec
95
- requirement: &70204688866620 !ruby/object:Gem::Requirement
95
+ requirement: &70263347754620 !ruby/object:Gem::Requirement
96
96
  none: false
97
97
  requirements:
98
98
  - - ! '>='
@@ -100,10 +100,10 @@ dependencies:
100
100
  version: '0'
101
101
  type: :development
102
102
  prerelease: false
103
- version_requirements: *70204688866620
103
+ version_requirements: *70263347754620
104
104
  - !ruby/object:Gem::Dependency
105
105
  name: mocha
106
- requirement: &70204688865980 !ruby/object:Gem::Requirement
106
+ requirement: &70263347754140 !ruby/object:Gem::Requirement
107
107
  none: false
108
108
  requirements:
109
109
  - - ! '>='
@@ -111,10 +111,10 @@ dependencies:
111
111
  version: '0'
112
112
  type: :development
113
113
  prerelease: false
114
- version_requirements: *70204688865980
114
+ version_requirements: *70263347754140
115
115
  - !ruby/object:Gem::Dependency
116
116
  name: ruby-debug19
117
- requirement: &70204688865360 !ruby/object:Gem::Requirement
117
+ requirement: &70263347753660 !ruby/object:Gem::Requirement
118
118
  none: false
119
119
  requirements:
120
120
  - - ! '>='
@@ -122,7 +122,7 @@ dependencies:
122
122
  version: '0'
123
123
  type: :development
124
124
  prerelease: false
125
- version_requirements: *70204688865360
125
+ version_requirements: *70263347753660
126
126
  description: Import CSV, SHP, and other files with data into a PostgreSQL table
127
127
  email:
128
128
  - andrew@vizzuality.com