split_pgdump 0.3.5 → 0.3.6
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.
- data/lib/split_pgdump.rb +39 -18
- metadata +2 -2
data/lib/split_pgdump.rb
CHANGED
@@ -7,7 +7,7 @@ require 'shellwords'
|
|
7
7
|
$debug = false
|
8
8
|
|
9
9
|
module SplitPgDump
|
10
|
-
VERSION = '0.3.
|
10
|
+
VERSION = '0.3.6'
|
11
11
|
end
|
12
12
|
|
13
13
|
class SplitPgDump::Worker
|
@@ -206,8 +206,8 @@ end
|
|
206
206
|
|
207
207
|
class SplitPgDump::Table
|
208
208
|
class NoColumn < StandardError; end
|
209
|
-
ONE_FILE_CACHE_SIZE =
|
210
|
-
TOTAL_CACHE_SIZE =
|
209
|
+
ONE_FILE_CACHE_SIZE = 3 * 128 * 1024
|
210
|
+
TOTAL_CACHE_SIZE = 4 * 128 * 1024
|
211
211
|
|
212
212
|
class OneFile
|
213
213
|
attr_reader :file_name, :cache_size
|
@@ -251,19 +251,38 @@ class SplitPgDump::Table
|
|
251
251
|
end
|
252
252
|
end
|
253
253
|
|
254
|
+
module DefaultName
|
255
|
+
def file_name(line)
|
256
|
+
@file_name
|
257
|
+
end
|
258
|
+
end
|
259
|
+
include DefaultName
|
260
|
+
|
261
|
+
module ComputeName
|
262
|
+
def file_name(line)
|
263
|
+
values = line.chomp.split("\t")
|
264
|
+
name = compute_name(values)
|
265
|
+
@file_name[name] ||= begin
|
266
|
+
name_strip = name.gsub(/\.\.|\s|\?|\*|'|"/, '_')
|
267
|
+
"#{table_schema}/#{name_strip}.dat"
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
254
272
|
attr_reader :table, :columns, :files, :sort_line, :sort_args
|
255
273
|
def initialize(dir, schema, name, columns, rule)
|
256
274
|
@dir = dir
|
257
275
|
@table = name
|
258
276
|
@schema = schema
|
259
277
|
@columns = columns.map{|c| c.sub(/^"(.+)"$/, '\\1')}
|
278
|
+
@file_name = "#{table_schema}.dat"
|
260
279
|
apply_rule rule
|
261
280
|
@files = {}
|
262
281
|
@total_cache_size = 0
|
263
282
|
end
|
264
283
|
|
265
|
-
def _mod(s,
|
266
|
-
|
284
|
+
def _mod(s, format, mod)
|
285
|
+
format % (s.to_i / mod * mod)
|
267
286
|
end
|
268
287
|
|
269
288
|
def apply_rule(rule)
|
@@ -281,7 +300,7 @@ class SplitPgDump::Table
|
|
281
300
|
if action[:mod]
|
282
301
|
mod_s = action[:mod]
|
283
302
|
mod = mod_s.to_i
|
284
|
-
field = "_mod(#{field}
|
303
|
+
field = "_mod(#{field}, '%0#{mod_s.size}d', #{mod})"
|
285
304
|
elsif action[:range]
|
286
305
|
field << "#{action[:range]}"
|
287
306
|
end
|
@@ -290,12 +309,15 @@ class SplitPgDump::Table
|
|
290
309
|
end
|
291
310
|
end
|
292
311
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
312
|
+
if split_string > ''
|
313
|
+
@file_name = {}
|
314
|
+
eval <<-"EOF"
|
315
|
+
def self.compute_name(values)
|
316
|
+
%{#{split_string}}
|
317
|
+
end
|
318
|
+
EOF
|
319
|
+
extend ComputeName
|
320
|
+
end
|
299
321
|
|
300
322
|
@sort_args = rule.sort_keys.map do |key|
|
301
323
|
i = @columns.find_index(key[:field])
|
@@ -312,13 +334,12 @@ class SplitPgDump::Table
|
|
312
334
|
@schema == 'public' ? @table : "#@schema/#@table"
|
313
335
|
end
|
314
336
|
|
315
|
-
def file_name(
|
316
|
-
|
337
|
+
def file_name(line)
|
338
|
+
@file_name
|
317
339
|
end
|
318
340
|
|
319
341
|
def add_line(line)
|
320
|
-
|
321
|
-
fname = file_name(values)
|
342
|
+
fname = file_name(line)
|
322
343
|
one_file = @files[fname] ||= OneFile.new(@dir, fname)
|
323
344
|
one_file.add_line(line)
|
324
345
|
@total_cache_size += line.size
|
@@ -336,8 +357,8 @@ class SplitPgDump::Table
|
|
336
357
|
|
337
358
|
def copy_lines
|
338
359
|
if block_given?
|
339
|
-
@files.each do |
|
340
|
-
yield "\\copy #{@table} (#{@columns.join(', ')}) from #{
|
360
|
+
@files.map{|n, one_file| one_file.file_name}.sort.each do |file_name|
|
361
|
+
yield "\\copy #{@table} (#{@columns.join(', ')}) from #{file_name}"
|
341
362
|
end
|
342
363
|
else
|
343
364
|
to_enum(:copy_lines)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: split_pgdump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -45,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
45
|
version: '0'
|
46
46
|
requirements: []
|
47
47
|
rubyforge_project:
|
48
|
-
rubygems_version: 1.8.
|
48
|
+
rubygems_version: 1.8.16
|
49
49
|
signing_key:
|
50
50
|
specification_version: 3
|
51
51
|
summary: split_pgdump is a tool for splitting postgresql dump in a managable set of
|