tapsoob 0.5.28 → 0.5.31
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/lib/tapsoob/operation.rb +14 -5
- data/lib/tapsoob/schema.rb +39 -4
- data/lib/tapsoob/utils.rb +10 -3
- data/lib/tapsoob/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bff0c57641151d932d224ec7b245a23c4b993eac3c8da25f10724208b46f5953
|
|
4
|
+
data.tar.gz: 186003a5f0156be1ebaac8f80ef44a3f985b23544a33a1e127067b776cf50d88
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c78e9d29d6247823deae5f9f1a86c59792b4e52c34f4d1536cdd16bc6168a2d38b3bfba434ec96b2be72d633e927f672578e70904387435a4152bc212ac544d5
|
|
7
|
+
data.tar.gz: 30a3507296d49349a3049fc2e24b61cbc98f49fdd0c38ce05f1714aefa0a598eed832ac5826c213f982b549708b566cc263053acf085b86ecc9fa7beb4ac6837
|
data/lib/tapsoob/operation.rb
CHANGED
|
@@ -183,7 +183,8 @@ module Tapsoob
|
|
|
183
183
|
|
|
184
184
|
progress = ProgressBar.new('Schema', tables.size)
|
|
185
185
|
tables.each do |table_name, count|
|
|
186
|
-
|
|
186
|
+
# Reuse existing db connection for better performance
|
|
187
|
+
schema_data = Tapsoob::Schema.dump_table(db, table_name, @opts.slice(:indexes, :same_db))
|
|
187
188
|
log.debug "Table: #{table_name}\n#{schema_data}\n"
|
|
188
189
|
output = Tapsoob::Utils.export_schema(dump_path, table_name, schema_data)
|
|
189
190
|
puts output if dump_path.nil? && output
|
|
@@ -405,7 +406,8 @@ module Tapsoob
|
|
|
405
406
|
progress = ProgressBar.new('Schema', tables.size)
|
|
406
407
|
tables.each do |table, count|
|
|
407
408
|
log.debug "Loading '#{table}' schema\n"
|
|
408
|
-
|
|
409
|
+
# Reuse existing db connection for better performance
|
|
410
|
+
Tapsoob::Utils.load_schema(dump_path, db, table)
|
|
409
411
|
progress.inc(1)
|
|
410
412
|
end
|
|
411
413
|
progress.finish
|
|
@@ -436,7 +438,9 @@ module Tapsoob
|
|
|
436
438
|
log.info "#{tables.size} tables, #{format_number(record_count)} records"
|
|
437
439
|
|
|
438
440
|
tables.each do |table_name, count|
|
|
439
|
-
|
|
441
|
+
# Skip if data file doesn't exist or has no data
|
|
442
|
+
data_file = File.join(dump_path, "data", "#{table_name}.json")
|
|
443
|
+
next unless File.exist?(data_file) && count > 0
|
|
440
444
|
db[table_name.to_sym].truncate if @opts[:purge]
|
|
441
445
|
stream = Tapsoob::DataStream.factory(db, {
|
|
442
446
|
:table_name => table_name,
|
|
@@ -532,8 +536,13 @@ module Tapsoob
|
|
|
532
536
|
tbls = Dir.glob(File.join(dump_path, "schemas", "*")).map { |path| File.basename(path, ".rb") }
|
|
533
537
|
tbls.each do |table|
|
|
534
538
|
if File.exist?(File.join(dump_path, "data", "#{table}.json"))
|
|
535
|
-
|
|
536
|
-
|
|
539
|
+
# Read NDJSON format - each line is a separate JSON chunk
|
|
540
|
+
total_rows = 0
|
|
541
|
+
File.readlines(File.join(dump_path, "data", "#{table}.json")).each do |line|
|
|
542
|
+
chunk = JSON.parse(line.strip)
|
|
543
|
+
total_rows += chunk["data"].size if chunk["data"]
|
|
544
|
+
end
|
|
545
|
+
tables_with_counts[table] = total_rows
|
|
537
546
|
else
|
|
538
547
|
tables_with_counts[table] = 0
|
|
539
548
|
end
|
data/lib/tapsoob/schema.rb
CHANGED
|
@@ -31,9 +31,11 @@ END_MIG
|
|
|
31
31
|
template.result(binding)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
def dump_table(
|
|
34
|
+
def dump_table(database_url_or_db, table, options)
|
|
35
35
|
table = table.to_sym
|
|
36
|
-
|
|
36
|
+
# Accept either a database URL or an existing connection object
|
|
37
|
+
if database_url_or_db.is_a?(Sequel::Database)
|
|
38
|
+
db = database_url_or_db
|
|
37
39
|
db.extension :schema_dumper
|
|
38
40
|
<<END_MIG
|
|
39
41
|
Class.new(Sequel::Migration) do
|
|
@@ -46,6 +48,21 @@ Class.new(Sequel::Migration) do
|
|
|
46
48
|
end
|
|
47
49
|
end
|
|
48
50
|
END_MIG
|
|
51
|
+
else
|
|
52
|
+
Sequel.connect(database_url_or_db) do |db|
|
|
53
|
+
db.extension :schema_dumper
|
|
54
|
+
<<END_MIG
|
|
55
|
+
Class.new(Sequel::Migration) do
|
|
56
|
+
def up
|
|
57
|
+
#{db.dump_table_schema(table, options)}
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def down
|
|
61
|
+
drop_table("#{table}", if_exists: true)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
END_MIG
|
|
65
|
+
end
|
|
49
66
|
end
|
|
50
67
|
end
|
|
51
68
|
|
|
@@ -86,8 +103,10 @@ END_MIG
|
|
|
86
103
|
JSON.generate(idxs)
|
|
87
104
|
end
|
|
88
105
|
|
|
89
|
-
def load(
|
|
90
|
-
|
|
106
|
+
def load(database_url_or_db, schema, options = { drop: false })
|
|
107
|
+
# Accept either a database URL or an existing connection object
|
|
108
|
+
if database_url_or_db.is_a?(Sequel::Database)
|
|
109
|
+
db = database_url_or_db
|
|
91
110
|
db.extension :schema_dumper
|
|
92
111
|
klass = eval(schema)
|
|
93
112
|
if options[:drop]
|
|
@@ -101,6 +120,22 @@ END_MIG
|
|
|
101
120
|
db.run("SET foreign_key_checks = 1") if [:mysql, :mysql2].include?(db.adapter_scheme)
|
|
102
121
|
end
|
|
103
122
|
klass.apply(db, :up)
|
|
123
|
+
else
|
|
124
|
+
Sequel.connect(database_url_or_db) do |db|
|
|
125
|
+
db.extension :schema_dumper
|
|
126
|
+
klass = eval(schema)
|
|
127
|
+
if options[:drop]
|
|
128
|
+
# Start special hack for MySQL
|
|
129
|
+
db.run("SET foreign_key_checks = 0") if [:mysql, :mysql2].include?(db.adapter_scheme)
|
|
130
|
+
|
|
131
|
+
# Run down migration
|
|
132
|
+
klass.apply(db, :down)
|
|
133
|
+
|
|
134
|
+
# End special hack for MySQL
|
|
135
|
+
db.run("SET foreign_key_checks = 1") if [:mysql, :mysql2].include?(db.adapter_scheme)
|
|
136
|
+
end
|
|
137
|
+
klass.apply(db, :up)
|
|
138
|
+
end
|
|
104
139
|
end
|
|
105
140
|
end
|
|
106
141
|
|
data/lib/tapsoob/utils.rb
CHANGED
|
@@ -161,9 +161,16 @@ Data : #{data}
|
|
|
161
161
|
end
|
|
162
162
|
end
|
|
163
163
|
|
|
164
|
-
def load_schema(dump_path,
|
|
165
|
-
|
|
166
|
-
|
|
164
|
+
def load_schema(dump_path, database_url_or_db, table)
|
|
165
|
+
schema_file = File.join(dump_path, "schemas", "#{table}.rb")
|
|
166
|
+
schema_content = File.read(schema_file)
|
|
167
|
+
|
|
168
|
+
# If we have a connection object, use it directly for better performance
|
|
169
|
+
if database_url_or_db.is_a?(Sequel::Database)
|
|
170
|
+
Tapsoob::Schema.load(database_url_or_db, schema_content)
|
|
171
|
+
else
|
|
172
|
+
schema_bin(:load, database_url_or_db, schema_file)
|
|
173
|
+
end
|
|
167
174
|
end
|
|
168
175
|
|
|
169
176
|
def load_indexes(database_url, index)
|
data/lib/tapsoob/version.rb
CHANGED