database_sanitizer 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/database_sanitizer/version.rb +1 -1
- data/lib/database_sanitizer.rb +12 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddcfff1fe892484023111ceca111ae9e0b7cfc15
|
4
|
+
data.tar.gz: be4dfe4874735872815bbae6ba55fe959092f359
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8751235e69d52bd02dc702a6a451e5c2ebdfa288a6e7f4a833428503afe9e59d613503a052fbe1fd67088cbb3378723814aa90dafa7eeb73d363898da560a34
|
7
|
+
data.tar.gz: e335a6f3adae02e04458793c7c0cd4f8dc430d23b3b91314c8b70afc67bc00ce85654688cf4d70e8d8907b3f5dec2cecac9b3fde6c05a83e96abc7af102547d2
|
data/lib/database_sanitizer.rb
CHANGED
@@ -3,7 +3,7 @@ require 'active_record/comments'
|
|
3
3
|
require 'progress'
|
4
4
|
|
5
5
|
module DatabaseSanitizer
|
6
|
-
CHUNK_SIZE =
|
6
|
+
CHUNK_SIZE = (ENV['CHUNK_SIZE'] || "1000").to_i
|
7
7
|
class Source < ActiveRecord::Base
|
8
8
|
end
|
9
9
|
end
|
@@ -63,20 +63,22 @@ module DatabaseSanitizer
|
|
63
63
|
|
64
64
|
tables.with_progress('Exporting').each do |table|
|
65
65
|
q_table = dest.quote_table_name table
|
66
|
-
|
66
|
+
s_table = table.to_sym
|
67
|
+
sel_query = "SELECT * FROM #{q_table} LIMIT #{CHUNK_SIZE} OFFSET "
|
67
68
|
get_chunks(table).times_with_progress(table.rjust max_tbl_name_len) do |chunk_i|
|
68
69
|
offset = chunk_i * CHUNK_SIZE
|
69
|
-
result = src.exec_query
|
70
|
+
result = src.exec_query sel_query + offset.to_s
|
70
71
|
cols = result.columns.map { |col| dest.quote_column_name col }.join ','
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
dest.insert_sql "INSERT INTO #{q_table} (#{cols}) VALUES (#{values.join ','})"
|
72
|
+
ins_query_part = "INSERT INTO #{q_table} (#{cols}) VALUES ("
|
73
|
+
ins_query = StringIO.new
|
74
|
+
result.rows.each_with_index do |src_row, row_i|
|
75
|
+
values = result.columns.each_with_index.map do |col, col_i|
|
76
|
+
transformer = transformers[s_table][col.to_sym]
|
77
|
+
dest.quote transformer ? transformer.(offset + row_i, src_row[col_i]) : src_row[col_i]
|
78
78
|
end
|
79
|
+
ins_query << ins_query_part << values.join(',') << '); '
|
79
80
|
end
|
81
|
+
dest.exec_query ins_query.string
|
80
82
|
end
|
81
83
|
end
|
82
84
|
end
|