db-purger 0.2.2 → 0.2.5

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: 3d0ca2166438859558fecf9ba8a9e0a2fb4b7763467360551d428269e4cf7aa5
4
- data.tar.gz: 50a53cebe730dc8240523d557997ca6186fd7ad87a2b2d6da39ac427e217204b
3
+ metadata.gz: 8a9cf35c804bae7cea5b7406c024fa04ab548b13405efdd7cfc5be81f28b15cd
4
+ data.tar.gz: a6470f9cbd9a857257fe9a7bd783c8e23c50d732dc3ba8db273efa6e5b6d4e9e
5
5
  SHA512:
6
- metadata.gz: 73f96ec383727353572583c2d182ac42e191fe50a7bd023d924255fba677ddb7fb806002c4417503a268cd62c1db61b23c3d4edf60ae14889d6c9f3fa3aff948
7
- data.tar.gz: '09b8e2e7f5067ad8c92bf05211d5ddad143807065389d29f4848135534db8c5155418eb75e006f65819b0a47231b2fb4a91fc8b42effa0a65918018f59dd5528'
6
+ metadata.gz: d3cbcf1d21d79937369685f02d1ad9476adf4cf69423a8b7686adb3d277d71263e8ce94990400b2455c94fb5c191e7b29846003afe99b6cce87a706d6dc65c37
7
+ data.tar.gz: c63a4909bb8b3a45f745165807872ef9b0d3183e1a7bfce6a3007726f33af4c7fc0e5925425cd699b42704e42c8785accba83fa5878f65bae2fb3d7a5b1aa9b0
@@ -15,8 +15,6 @@ module DBPurger
15
15
  end
16
16
 
17
17
  def build(base_table_name, field)
18
- write('DBPurger::PlanBuilder.build do')
19
- @indent_depth += 1
20
18
  write_table('base', base_table_name.to_s, field, [], nil)
21
19
  line_break
22
20
  model = find_model_for_table(base_table_name)
@@ -27,8 +25,6 @@ module DBPurger
27
25
  add_child_tables(child_models, foreign_key, 0)
28
26
  end
29
27
  ignore_missing_tables
30
- @indent_depth -= 1
31
- write('end')
32
28
  @output
33
29
  end
34
30
 
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DBPurger
4
+ # DBPurger::Executor used to execute a purge plan with verification
5
+ class Executor
6
+ attr_writer :error_io
7
+
8
+ def initialize(database, plan, options = {})
9
+ @database = database
10
+ @plan = plan.is_a?(Plan) ? plan : load_plan(plan)
11
+ setup_config(options)
12
+ @error_io = $stderr
13
+ end
14
+
15
+ def purge!(purge_value)
16
+ raise('purge_value is nil') if purge_value.nil?
17
+
18
+ @plan.purge!(@database, purge_value)
19
+ end
20
+
21
+ def verify!
22
+ return if plan_validator.valid?
23
+
24
+ output_plan_errors
25
+ raise('purge plan failed verification')
26
+ end
27
+
28
+ private
29
+
30
+ def plan_validator
31
+ @plan_validator ||= PlanValidator.new(@database, @plan)
32
+ end
33
+
34
+ def setup_config(options)
35
+ ::DBPurger.config.explain = options[:explain]
36
+ ::DBPurger.config.explain_file = options[:explain_file]
37
+ ::DBPurger.config.datetime_format = options[:datetime_format]
38
+ end
39
+
40
+ def load_plan(file)
41
+ PlanBuilder
42
+ .new(Plan.new)
43
+ .load_plan_file(file)
44
+ end
45
+
46
+ def output_plan_errors
47
+ plan_validator.errors.each do |field, error_msg|
48
+ @error_io.puts "#{field}: #{error_msg}"
49
+ end
50
+ end
51
+ end
52
+ end
@@ -58,12 +58,17 @@ module DBPurger
58
58
  helper.instance_eval(&block)
59
59
  end
60
60
 
61
+ def load_plan_file(file)
62
+ instance_eval(File.read(file))
63
+ @plan
64
+ end
65
+
61
66
  private
62
67
 
63
68
  def create_table(table_name, field, options, &block)
64
69
  table = Table.new(table_name, field)
65
70
  table.foreign_key = options[:foreign_key]
66
- table.batch_size = options[:batch_size]
71
+ table.batch_size = options[:batch_size] if options[:batch_size]
67
72
  table.conditions = options[:conditions]
68
73
  table.mark_deleted_field = options[:mark_deleted_field]
69
74
  table.mark_deleted_value = options[:mark_deleted_value]
data/lib/db-purger.rb CHANGED
@@ -4,6 +4,7 @@
4
4
  module DBPurger
5
5
  autoload :Config, 'db-purger/config'
6
6
  autoload :DynamicPlanBuilder, 'db-purger/dynamic_plan_builder'
7
+ autoload :Executor, 'db-purger/executor'
7
8
  autoload :Metrics, 'db-purger/metrics'
8
9
  autoload :MetricSubscriber, 'db-purger/metric_subscriber'
9
10
  autoload :PurgeTable, 'db-purger/purge_table'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db-purger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Youch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-19 00:00:00.000000000 Z
11
+ date: 2019-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dynamic-active-model
@@ -47,6 +47,7 @@ files:
47
47
  - lib/db-purger.rb
48
48
  - lib/db-purger/config.rb
49
49
  - lib/db-purger/dynamic_plan_builder.rb
50
+ - lib/db-purger/executor.rb
50
51
  - lib/db-purger/metric_subscriber.rb
51
52
  - lib/db-purger/metrics.rb
52
53
  - lib/db-purger/plan.rb