tapsoob 0.4.21 → 0.4.27

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6894559fc6e93ef21963e790ec461551355785551906af8b3919c562efe58917
4
- data.tar.gz: 01d3b9ae459ae41d598e7146cb7334d3e154fd28e71a617f52ee134bea00ebef
3
+ metadata.gz: f87d929aa027581755bc0a9cf313fc6532505a99ce68a1537a02539a1bbc4fd9
4
+ data.tar.gz: ea9242c530789c7175db850b178e7a824e77742c44c04f29731e9e5badb6fb0e
5
5
  SHA512:
6
- metadata.gz: fc5b9ce215d00c4966aa85e2c9c0d9270197a2bacc1f444b758bc3f7f9b03bfc26ccb250ccf69e0fefbf7db2c31b7b3778790c527607bee6515837f6169825d6
7
- data.tar.gz: 780dc83b47bf036f25182bb0e37b1f9f89db9f65a2a9889942eb2ba28fab872118f359e40c5a3abe014d8ec7aedcaa52aafc956e2a2eec8e268783061a6dc7be
6
+ metadata.gz: feea04845e17624632d56fa5258b8492040bb8078baa0fae7c5f7c0e99e3d4cd3158520d4a84d9aa4e2955e81a5a6a213e350f54b3ff48a820808a9718bb1df5
7
+ data.tar.gz: 182d6f6df58ff78e1e53e3539a5de2f8ccdec862255bb876b2b8828e890f51b3e4ba7d065fcecbe5d79dddd8c9e6f514b3a56ecdcb2d516d4825cbdcb6cc525b
@@ -12,7 +12,6 @@ module Tapsoob
12
12
  class DataStream < Thor
13
13
  desc "pull DATABASE_URL [DUMP_PATH]", "Pull data from a database."
14
14
  option :chunksize, desc: "Initial chunksize", default: 1000, type: :numeric, aliases: "-c"
15
- option :filter, desc: "Regex Filter for tables", type: :string, aliases: "-f"
16
15
  option :tables, desc: "Shortcut to filter on a list of tables", type: :array, aliases: "-t"
17
16
  option :"exclude-tables", desc: "Shortcut to exclude a list of tables", type: :array, aliases: "-e"
18
17
  option :progress, desc: "Show progress", default: true, type: :boolean, aliases: "-p"
@@ -24,7 +23,6 @@ module Tapsoob
24
23
 
25
24
  desc "push DATABASE_URL [DUMP_PATH]", "Push data to a database."
26
25
  option :chunksize, desc: "Initial chunksize", default: 1000, type: :numeric, aliases: "-c"
27
- option :filter, desc: "Regex Filter for tables", type: :string, aliases: "-f"
28
26
  option :tables, desc: "Shortcut to filter on a list of tables", type: :array, aliases: "-t"
29
27
  option :"exclude-tables", desc: "Shortcut to exclude a list of tables", type: :array, aliases: "-e"
30
28
  option :progress, desc: "Show progress", default: true, type: :boolean, aliases: "-p"
@@ -65,6 +63,7 @@ module Tapsoob
65
63
  # Default options
66
64
  opts = {
67
65
  progress: options[:progress],
66
+ tables: options[:tables],
68
67
  debug: options[:debug]
69
68
  }
70
69
 
@@ -78,15 +77,6 @@ module Tapsoob
78
77
  opts[:default_chunksize] = (options[:chunksize] < 10 ? 10 : options[:chunksize])
79
78
  end
80
79
 
81
- # Regex filter
82
- opts[:table_filter] = options[:filter] if options[:filter]
83
-
84
- # Table filter
85
- if options[:tables]
86
- r_tables = options[:tables].collect { |t| "^#{t}" }.join("|")
87
- opts[:table_filter] = "#{r_tables}"
88
- end
89
-
90
80
  # Exclude tables
91
81
  opts[:exclude_tables] = options[:"exclude-tables"] if options[:"exclude-tables"]
92
82
 
@@ -10,12 +10,12 @@ module Tapsoob
10
10
  module CLI
11
11
  class Root < Thor
12
12
  desc "pull DUMP_PATH DATABASE_URL", "Pull a dump from a database to a folder"
13
+ option :"schema-only", desc: "Don't transfer the data just schema", default: false, type: :boolean
13
14
  option :"skip-schema", desc: "Don't transfer the schema just data", default: false, type: :boolean, aliases: "-s"
14
15
  option :"indexes-first", desc: "Transfer indexes first before data", default: false, type: :boolean, aliases: "-i"
15
16
  option :resume, desc: "Resume a Tapsoob Session from a stored file", type: :string, aliases: "-r"
16
17
  option :chunksize, desc: "Initial chunksize", default: 1000, type: :numeric, aliases: "-c"
17
18
  option :"disable-compression", desc: "Disable Compression", default: false, type: :boolean, aliases: "-g"
18
- option :filter, desc: "Regex Filter for tables", type: :string, aliases: "-f"
19
19
  option :tables, desc: "Shortcut to filter on a list of tables", type: :array, aliases: "-t"
20
20
  option :"exclude-tables", desc: "Shortcut to exclude a list of tables", type: :array, aliases: "-e"
21
21
  option :debug, desc: "Enable debug messages", default: false, type: :boolean, aliases: "-d"
@@ -30,12 +30,12 @@ module Tapsoob
30
30
  end
31
31
 
32
32
  desc "push DUMP_PATH DATABASE_URL", "Push a previously tapsoob dump to a database"
33
+ option :"schema-only", desc: "Don't transfer the data just schema", default: false, type: :boolean
33
34
  option :"skip-schema", desc: "Don't transfer the schema just data", default: false, type: :boolean, aliases: "-s"
34
35
  option :"indexes-first", desc: "Transfer indexes first before data", default: false, type: :boolean, aliases: "-i"
35
36
  option :resume, desc: "Resume a Tapsoob Session from a stored file", type: :string, aliases: "-r"
36
37
  option :chunksize, desc: "Initial chunksize", default: 1000, type: :numeric, aliases: "-c"
37
38
  option :"disable-compression", desc: "Disable Compression", default: false, type: :boolean, aliases: "-g"
38
- option :filter, desc: "Regex Filter for tables", type: :string, aliases: "-f"
39
39
  option :tables, desc: "Shortcut to filter on a list of tables", type: :array, aliases: "-t"
40
40
  option :"exclude-tables", desc: "Shortcut to exclude a list of tables", type: :array, aliases: "-e"
41
41
  option :purge, desc: "Purge data in tables prior to performing the import", default: false, type: :boolean, aliases: "-p"
@@ -67,9 +67,11 @@ module Tapsoob
67
67
  def parse_opts(options)
68
68
  # Default options
69
69
  opts = {
70
+ schema_only: options[:"schema-only"],
70
71
  skip_schema: options[:"skip-schema"],
71
72
  indexes_first: options[:"indexes_first"],
72
73
  disable_compression: options[:"disable-compression"],
74
+ tables: options[:tables],
73
75
  debug: options[:debug]
74
76
  }
75
77
 
@@ -92,15 +94,6 @@ module Tapsoob
92
94
  opts[:default_chunksize] = (options[:chunksize] < 10 ? 10 : options[:chunksize])
93
95
  end
94
96
 
95
- # Regex filter
96
- opts[:table_filter] = options[:filter] if options[:filter]
97
-
98
- # Table filter
99
- if options[:tables]
100
- r_tables = options[:tables].collect { |t| "^#{t}" }.join("|")
101
- opts[:table_filter] = "#{r_tables}"
102
- end
103
-
104
97
  # Exclude tables
105
98
  opts[:exclude_tables] = options[:"exclude-tables"] if options[:"exclude-tables"]
106
99
 
@@ -21,6 +21,10 @@ module Tapsoob
21
21
  "op"
22
22
  end
23
23
 
24
+ def schema_only?
25
+ !!opts[:schema_only]
26
+ end
27
+
24
28
  def skip_schema?
25
29
  !!opts[:skip_schema]
26
30
  end
@@ -30,7 +34,7 @@ module Tapsoob
30
34
  end
31
35
 
32
36
  def table_filter
33
- opts[:table_filter]
37
+ opts[:tables] || []
34
38
  end
35
39
 
36
40
  def exclude_tables
@@ -38,19 +42,18 @@ module Tapsoob
38
42
  end
39
43
 
40
44
  def apply_table_filter(tables)
41
- return tables unless table_filter || exclude_tables
45
+ return tables if table_filter.empty? && exclude_tables.empty?
42
46
 
43
- re = table_filter ? Regexp.new(table_filter) : nil
44
47
  if tables.kind_of?(Hash)
45
48
  ntables = {}
46
49
  tables.each do |t, d|
47
- if !exclude_tables.include?(t.to_s) && (!re || !re.match(t.to_s).nil?)
50
+ if !exclude_tables.include?(t.to_s) && (!table_filter.empty? && table_filter.include?(t.to_s))
48
51
  ntables[t] = d
49
52
  end
50
53
  end
51
54
  ntables
52
55
  else
53
- tables.reject { |t| exclude_tables.include?(t.to_s) || (re && re.match(t.to_s).nil?) }
56
+ tables.reject { |t| exclude_tables.include?(t.to_s) }.select { |t| table_filter.include?(t.to_s) }
54
57
  end
55
58
  end
56
59
 
@@ -168,7 +171,7 @@ module Tapsoob
168
171
  end
169
172
  setup_signal_trap
170
173
  pull_partial_data if resuming?
171
- pull_data
174
+ pull_data unless schema_only?
172
175
  pull_indexes if !indexes_first? && !skip_schema?
173
176
  pull_reset_sequences
174
177
  end
@@ -182,7 +185,7 @@ module Tapsoob
182
185
  schema_data = Tapsoob::Schema.dump_table(database_url, table_name)
183
186
  log.debug "Table: #{table_name}\n#{schema_data}\n"
184
187
  output = Tapsoob::Utils.export_schema(dump_path, table_name, schema_data)
185
- puts output if output
188
+ puts output if dump_path.nil? && output
186
189
  progress.inc(1)
187
190
  end
188
191
  progress.finish
@@ -290,7 +293,7 @@ module Tapsoob
290
293
  def pull_indexes
291
294
  log.info "Receiving indexes"
292
295
 
293
- raw_idxs = Tapsoob::Utils.schema_bin(:indexes_individual, database_url)
296
+ raw_idxs = Tapsoob::Schema.indexes_individual(database_url)
294
297
  idxs = (raw_idxs && raw_idxs.length >= 2 ? JSON.parse(raw_idxs) : {})
295
298
 
296
299
  apply_table_filter(idxs).each do |table, indexes|
@@ -298,7 +301,7 @@ module Tapsoob
298
301
  progress = ProgressBar.new(table, indexes.size)
299
302
  indexes.each do |idx|
300
303
  output = Tapsoob::Utils.export_indexes(dump_path, table, idx)
301
- puts output if output
304
+ puts output if dump_path.nil? && output
302
305
  progress.inc(1)
303
306
  end
304
307
  progress.finish
@@ -309,7 +312,7 @@ module Tapsoob
309
312
  log.info "Resetting sequences"
310
313
 
311
314
  output = Tapsoob::Utils.schema_bin(:reset_db_sequences, database_url)
312
- puts output if output
315
+ puts output if dump_path.nil? && output
313
316
  end
314
317
  end
315
318
 
@@ -330,7 +333,7 @@ module Tapsoob
330
333
  end
331
334
  setup_signal_trap
332
335
  push_partial_data if resuming?
333
- push_data
336
+ push_data unless schema_only?
334
337
  push_indexes if !indexes_first? && !skip_schema?
335
338
  push_reset_sequences
336
339
  end
@@ -393,7 +396,7 @@ module Tapsoob
393
396
  log.info "#{tables.size} tables, #{format_number(record_count)} records"
394
397
 
395
398
  tables.each do |table_name, count|
396
- next unless File.exists?(File.join(dump_path, "data", "#{table_name}.json")) || JSON.parse(File.read(File.join(dump_path, "data", "#{table}.json")))["data"].size == 0
399
+ next unless File.exists?(File.join(dump_path, "data", "#{table_name}.json")) || File.exists?(File.join(dump_path, "data", "#{table_name}.json")) && JSON.parse(File.read(File.join(dump_path, "data", "#{table_name}.json")))["data"].size == 0
397
400
  db[table_name.to_sym].truncate if @opts[:purge]
398
401
  stream = Tapsoob::DataStream.factory(db, {
399
402
  :table_name => table_name,
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Tapsoob
3
- VERSION = "0.4.21".freeze
3
+ VERSION = "0.4.27".freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tapsoob
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.21
4
+ version: 0.4.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Félix Bellanger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-10-19 00:00:00.000000000 Z
12
+ date: 2022-01-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ripl
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  - !ruby/object:Gem::Version
150
150
  version: '0'
151
151
  requirements: []
152
- rubygems_version: 3.1.6
152
+ rubygems_version: 3.2.32
153
153
  signing_key:
154
154
  specification_version: 4
155
155
  summary: Simple tool to import/export databases.