db_subsetter 0.3.0 → 0.4.0
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.
- checksums.yaml +4 -4
- data/db_subsetter.gemspec +1 -0
- data/lib/db_subsetter/exporter.rb +15 -1
- data/lib/db_subsetter/scrambler.rb +28 -0
- data/lib/db_subsetter/version.rb +1 -1
- data/lib/db_subsetter.rb +1 -0
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cbd626cd24132c2e8db14c89ecb66c300350886
|
4
|
+
data.tar.gz: f7171ef20aded756e45b11a04c5072ab0303e1ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd3d89c74237f6a7c942bfb72561e3eaef426e34c3919f1c0b6651287e76650bebec068eb1b5b81c1dcf2c0d7959c43e1b5682be51ba6f21b62234afab1d4107
|
7
|
+
data.tar.gz: d9d8f8a4c5483e12fb9fe10cfee561c656fa67205c3968cc2c2cac6ca281ab7d76d9c8787b13534445434a0939f6477102ff7b2318c9e5e72effc282936280c1
|
data/db_subsetter.gemspec
CHANGED
@@ -49,7 +49,13 @@ module DbSubsetter
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
def add_scrambler(scrambler)
|
53
|
+
@scramblers << scrambler
|
54
|
+
end
|
52
55
|
|
56
|
+
def initialize
|
57
|
+
@scramblers = []
|
58
|
+
end
|
53
59
|
|
54
60
|
private
|
55
61
|
def max_unfiltered_rows
|
@@ -60,6 +66,7 @@ module DbSubsetter
|
|
60
66
|
@max_filtered_rows || 2000
|
61
67
|
end
|
62
68
|
|
69
|
+
# this is the batch size we insert into sqlite, which seems to be a reasonable balance of speed and memory usage
|
63
70
|
def insert_batch_size
|
64
71
|
250
|
65
72
|
end
|
@@ -108,6 +115,13 @@ module DbSubsetter
|
|
108
115
|
end
|
109
116
|
end
|
110
117
|
|
118
|
+
def scramble_data(table, data)
|
119
|
+
@scramblers.each do |scrambler|
|
120
|
+
data = scrambler.scramble(table, data)
|
121
|
+
end
|
122
|
+
data
|
123
|
+
end
|
124
|
+
|
111
125
|
def export_table(table)
|
112
126
|
print "Exporting: #{table} (#{pages(table)} pages)" if @verbose
|
113
127
|
$stdout.flush if @verbose
|
@@ -124,7 +138,7 @@ module DbSubsetter
|
|
124
138
|
|
125
139
|
records = ActiveRecord::Base.connection.select_rows( sql )
|
126
140
|
records.each_slice(insert_batch_size) do |rows|
|
127
|
-
@output.execute("INSERT INTO #{table.underscore} (data) VALUES #{ Array.new(rows.size){"(?)"}.join(",")}", rows.map{|x| cleanup_types(x)}.map(&:to_json) )
|
141
|
+
@output.execute("INSERT INTO #{table.underscore} (data) VALUES #{ Array.new(rows.size){"(?)"}.join(",")}", rows.map{|x| scramble_data(table, cleanup_types(x))}.map(&:to_json) )
|
128
142
|
rows_exported += rows.size
|
129
143
|
end
|
130
144
|
print "." if @verbose
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'random-word'
|
2
|
+
|
3
|
+
module DbSubsetter
|
4
|
+
class Scrambler
|
5
|
+
def scramble(table, row)
|
6
|
+
scramble_method = "scramble_#{table.downcase}"
|
7
|
+
if self.respond_to? scramble_method
|
8
|
+
self.send(scramble_method, row)
|
9
|
+
else
|
10
|
+
row
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@column_index_cache = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
def scramble_column(table, column, row_data, value)
|
20
|
+
row_data[column_index(table, column)] = value
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def column_index(table, column)
|
25
|
+
@column_index_cache["#{table}##{column}"] ||= ActiveRecord::Base.connection.columns(table).map{|table| table.name}.index(column.to_s)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/db_subsetter/version.rb
CHANGED
data/lib/db_subsetter.rb
CHANGED
@@ -2,6 +2,7 @@ require "db_subsetter/version"
|
|
2
2
|
require "db_subsetter/filter"
|
3
3
|
require "db_subsetter/exporter"
|
4
4
|
require "db_subsetter/importer"
|
5
|
+
require "db_subsetter/scrambler"
|
5
6
|
require "db_subsetter/dialect/generic"
|
6
7
|
require "db_subsetter/dialect/my_sql"
|
7
8
|
require "db_subsetter/dialect/ms_sql"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: db_subsetter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Francis
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: random-word
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description:
|
84
98
|
email:
|
85
99
|
- joe@lostapathy.com
|
@@ -103,6 +117,7 @@ files:
|
|
103
117
|
- lib/db_subsetter/exporter.rb
|
104
118
|
- lib/db_subsetter/filter.rb
|
105
119
|
- lib/db_subsetter/importer.rb
|
120
|
+
- lib/db_subsetter/scrambler.rb
|
106
121
|
- lib/db_subsetter/version.rb
|
107
122
|
homepage: https://github.com/lostapathy/db_subsetter
|
108
123
|
licenses:
|