db-purger 0.2.0 → 0.2.2

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: f85bace783d6c2c4bf0526a608326a9d15ee3dc0babd439a2dd86c22ab304343
4
- data.tar.gz: fa1f889ecf967b73357d2764764e01a3ba7a52a9dea5737b7008e9c87edf953b
3
+ metadata.gz: 3d0ca2166438859558fecf9ba8a9e0a2fb4b7763467360551d428269e4cf7aa5
4
+ data.tar.gz: 50a53cebe730dc8240523d557997ca6186fd7ad87a2b2d6da39ac427e217204b
5
5
  SHA512:
6
- metadata.gz: cc7a13db98536483613543736ed8a0bd03dc5dd1076060a4b1735e7b5499634d1e80e955cd714ce67785dcf42b0841b47ebefbaecae9143b4366c7d27be80786
7
- data.tar.gz: bf6d5fa8f36eaf89087056673d1e49bfa74d4141321c078c5a0b0414fe58b8d64f1409b80838a2d05a7ae163cf11f0cf345dd2d812020a8adb4a1e5020ed1202
6
+ metadata.gz: 73f96ec383727353572583c2d182ac42e191fe50a7bd023d924255fba677ddb7fb806002c4417503a268cd62c1db61b23c3d4edf60ae14889d6c9f3fa3aff948
7
+ data.tar.gz: '09b8e2e7f5067ad8c92bf05211d5ddad143807065389d29f4848135534db8c5155418eb75e006f65819b0a47231b2fb4a91fc8b42effa0a65918018f59dd5528'
@@ -11,12 +11,13 @@ module DBPurger
11
11
  @database = database
12
12
  @output = ''.dup
13
13
  @indent_depth = 0
14
- write('DBPurger::PlanBuilder.build do')
15
- @indent_depth += 1
14
+ @tables = []
16
15
  end
17
16
 
18
17
  def build(base_table_name, field)
19
- write("base_table(#{base_table_name.to_sym.inspect}, #{field.to_sym.inspect})")
18
+ write('DBPurger::PlanBuilder.build do')
19
+ @indent_depth += 1
20
+ write_table('base', base_table_name.to_s, field, [], nil)
20
21
  line_break
21
22
  model = find_model_for_table(base_table_name)
22
23
  foreign_key = foreign_key_name(model)
@@ -25,6 +26,7 @@ module DBPurger
25
26
  line_break
26
27
  add_child_tables(child_models, foreign_key, 0)
27
28
  end
29
+ ignore_missing_tables
28
30
  @indent_depth -= 1
29
31
  write('end')
30
32
  @output
@@ -86,6 +88,7 @@ module DBPurger
86
88
  end
87
89
 
88
90
  def write_table(table_type, table_name, field, child_models, foreign_key)
91
+ @tables << table_name
89
92
  if child_models.empty?
90
93
  write("#{table_type}_table(#{table_name.to_sym.inspect}, #{field.to_sym.inspect})")
91
94
  else
@@ -94,5 +97,15 @@ module DBPurger
94
97
  write('end')
95
98
  end
96
99
  end
100
+
101
+ def ignore_missing_tables
102
+ missing_tables = @database.models.map(&:table_name) - @tables
103
+ return if missing_tables.empty?
104
+
105
+ line_break
106
+ missing_tables.each do |table_name|
107
+ write("ignore_table #{table_name.to_sym.inspect}")
108
+ end
109
+ end
97
110
  end
98
111
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db-purger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Youch