bulk_dependency_eraser 2.0.0 → 2.1.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4bda32570c3319238a5ea03f6a71cbae1e20015caf5fe7bdba78cab3c7883a7
|
4
|
+
data.tar.gz: 9e371750cd1a05b54bfe724873daaf2c7e9aa66942f168d6417505a1427d46c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33130d09c651a9757af826cbbd5e1363a8f136a3d6e3bf1e2a128dad776185b544fd75a493013cd28d279690094e90cc3dc0f3b23597704df9842eb80e215808
|
7
|
+
data.tar.gz: 27f4e6014155961a1286f2d1f490a7ca2709fd2b9594a7c8ab3fb3164c26bbdf99e8609c5494e15e8595b0db9eee94d485a20a772f5a37d58554b497eaee5154
|
@@ -1,7 +1,29 @@
|
|
1
1
|
module BulkDependencyEraser
|
2
2
|
class Deleter < Base
|
3
|
+
DEFAULT_DB_DELETE_ALL_WRAPPER = ->(block) do
|
4
|
+
begin
|
5
|
+
block.call
|
6
|
+
rescue StandardError => e
|
7
|
+
report_error("Issue attempting to delete '#{current_class_name}': #{e.class.name} - #{e.message}")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
3
11
|
DEFAULT_OPTS = {
|
4
12
|
verbose: false,
|
13
|
+
# Runs once, all deletions occur within it
|
14
|
+
# - useful if you wanted to implement a rollback:
|
15
|
+
# - i.e:
|
16
|
+
# db_delete_all_wrapper: lambda do |block|
|
17
|
+
# ActiveRecord::Base.transaction do
|
18
|
+
# begin
|
19
|
+
# block.call
|
20
|
+
# rescue StandardError => e
|
21
|
+
# report_error("Issue attempting to delete '#{current_class_name}': #{e.class.name} - #{e.message}")
|
22
|
+
# raise ActiveRecord::Rollback
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
db_delete_all_wrapper: self::DEFAULT_DB_DELETE_ALL_WRAPPER,
|
5
27
|
db_delete_wrapper: self::DEFAULT_DB_WRITE_WRAPPER,
|
6
28
|
# Set to true if you want 'ActiveRecord::InvalidForeignKey' errors raised during deletions
|
7
29
|
enable_invalid_foreign_key_detection: false,
|
@@ -37,8 +59,7 @@ module BulkDependencyEraser
|
|
37
59
|
end
|
38
60
|
|
39
61
|
current_class_name = 'N/A'
|
40
|
-
|
41
|
-
# IDs should have already been reversed in builder
|
62
|
+
delete_all_in_db do
|
42
63
|
class_names_and_ids.keys.reverse.each do |class_name|
|
43
64
|
current_class_name = class_name
|
44
65
|
ids = class_names_and_ids[class_name].reverse
|
@@ -57,8 +78,6 @@ module BulkDependencyEraser
|
|
57
78
|
end
|
58
79
|
end
|
59
80
|
end
|
60
|
-
rescue StandardError => e
|
61
|
-
report_error("Issue attempting to delete '#{current_class_name}': #{e.class.name} - #{e.message}")
|
62
81
|
end
|
63
82
|
|
64
83
|
return errors.none?
|
@@ -116,6 +135,13 @@ module BulkDependencyEraser
|
|
116
135
|
def delete_in_db(&block)
|
117
136
|
puts "Deleting from DB..." if opts_c.verbose
|
118
137
|
opts_c.db_delete_wrapper.call(block)
|
138
|
+
puts "Deleting from DB complete." if opts_c.verbose
|
139
|
+
end
|
140
|
+
|
141
|
+
def delete_all_in_db(&block)
|
142
|
+
puts "Deleting all from DB..." if opts_c.verbose
|
143
|
+
opts_c.db_delete_all_wrapper.call(block)
|
144
|
+
puts "Deleting all from DB complete." if opts_c.verbose
|
119
145
|
end
|
120
146
|
end
|
121
147
|
end
|
@@ -1,7 +1,29 @@
|
|
1
1
|
module BulkDependencyEraser
|
2
2
|
class Nullifier < Base
|
3
|
+
DEFAULT_DB_NULLIFY_ALL_WRAPPER = lambda do |block|
|
4
|
+
begin
|
5
|
+
block.call
|
6
|
+
rescue StandardError => e
|
7
|
+
report_error("Issue attempting to nullify '#{current_class_name}' column '#{current_column}': #{e.class.name} - #{e.message}")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
3
11
|
DEFAULT_OPTS = {
|
4
12
|
verbose: false,
|
13
|
+
# Runs once, all deletions occur within it
|
14
|
+
# - useful if you wanted to implement a rollback:
|
15
|
+
# - i.e:
|
16
|
+
# db_nullify_all_wrapper: lambda do |block|
|
17
|
+
# ActiveRecord::Base.transaction do
|
18
|
+
# begin
|
19
|
+
# block.call
|
20
|
+
# rescue StandardError => e
|
21
|
+
# report_error("Issue attempting to nullify '#{current_class_name}': #{e.class.name} - #{e.message}")
|
22
|
+
# raise ActiveRecord::Rollback
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
db_nullify_all_wrapper: self::DEFAULT_DB_NULLIFY_ALL_WRAPPER,
|
5
27
|
db_nullify_wrapper: self::DEFAULT_DB_WRITE_WRAPPER,
|
6
28
|
# Set to true if you want 'ActiveRecord::InvalidForeignKey' errors raised during nullifications
|
7
29
|
# - I can't think of a use-case where a nullification would generate an invalid key error
|
@@ -91,7 +113,7 @@ module BulkDependencyEraser
|
|
91
113
|
def execute
|
92
114
|
current_class_name = 'N/A'
|
93
115
|
current_column = 'N/A'
|
94
|
-
|
116
|
+
nullify_all_in_db do
|
95
117
|
# column_and_ids should have already been reversed in builder
|
96
118
|
class_names_columns_and_ids.keys.reverse.each do |class_name|
|
97
119
|
current_class_name = class_name
|
@@ -117,8 +139,6 @@ module BulkDependencyEraser
|
|
117
139
|
end
|
118
140
|
end
|
119
141
|
end
|
120
|
-
rescue StandardError => e
|
121
|
-
report_error("Issue attempting to nullify '#{current_class_name}' column '#{current_column}': #{e.class.name} - #{e.message}")
|
122
142
|
end
|
123
143
|
|
124
144
|
return errors.none?
|
@@ -145,6 +165,9 @@ module BulkDependencyEraser
|
|
145
165
|
opts_c.disable_nullify_batching.nil? ? opts_c.disable_batching : opts_c.disable_nullify_batching
|
146
166
|
end
|
147
167
|
|
168
|
+
# @param klass [ActiveRecord::Base]
|
169
|
+
# @param columns [Symbol | String | Array<String | Symbol>]
|
170
|
+
# @param ids [Array[String | Integer]]
|
148
171
|
def nullify_by_klass_column_and_ids klass, columns, ids
|
149
172
|
query = klass.unscoped
|
150
173
|
query = custom_scope_for_query(query)
|
@@ -183,6 +206,13 @@ module BulkDependencyEraser
|
|
183
206
|
def nullify_in_db(&block)
|
184
207
|
puts "Nullifying from DB..." if opts_c.verbose
|
185
208
|
opts_c.db_nullify_wrapper.call(block)
|
209
|
+
puts "Nullifying from DB complete." if opts_c.verbose
|
210
|
+
end
|
211
|
+
|
212
|
+
def nullify_all_in_db(&block)
|
213
|
+
puts "Nullifying all from DB..." if opts_c.verbose
|
214
|
+
opts_c.db_nullify_all_wrapper.call(block)
|
215
|
+
puts "Nullifying all from DB complete." if opts_c.verbose
|
186
216
|
end
|
187
217
|
|
188
218
|
end
|