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 +4 -4
- data/lib/db-purger/dynamic_plan_builder.rb +16 -3
- 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: 3d0ca2166438859558fecf9ba8a9e0a2fb4b7763467360551d428269e4cf7aa5
|
4
|
+
data.tar.gz: 50a53cebe730dc8240523d557997ca6186fd7ad87a2b2d6da39ac427e217204b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
15
|
-
@indent_depth += 1
|
14
|
+
@tables = []
|
16
15
|
end
|
17
16
|
|
18
17
|
def build(base_table_name, field)
|
19
|
-
write(
|
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
|