bulk_dependency_eraser 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 734c542b83d1cf827cadf8a8a41c30d8a86ebe7f98e539e0bdce4777f917c2e9
|
4
|
+
data.tar.gz: fedb350237abe9898c2d54077db57c1c500b76c99c6913431c2445f5fd49293a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b69927dd186b6eac307ff85a5bd06783245c5173a6d890ff29a8abb42edbf8df105a3ed592cf3ae92f649c4547f32c289316b83ae7f02d19233a05d9a2a5d47
|
7
|
+
data.tar.gz: 9a4febdbdd779faf17bc332b8853c41bb727e722fea564ed45a8b871ee53f8e4677983c2459a4894a4304c90397a48fa927d41609e4558033ee24c43badbc4b7
|
@@ -1,12 +1,22 @@
|
|
1
1
|
module BulkDependencyEraser
|
2
2
|
class Base
|
3
|
+
# Default Custom Scope for all classes, no effect.
|
4
|
+
DEFAULT_SCOPE_WRAPPER = ->(query) { nil }
|
5
|
+
# Default Custom Scope for mapped-by-name classes, no effect.
|
6
|
+
DEFAULT_KLASS_MAPPED_SCOPE_WRAPPER = ->(query) { query }
|
7
|
+
|
3
8
|
DEFAULT_OPTS = {
|
4
9
|
# Applied to all queries. Useful for taking advantage of specific indexes
|
10
|
+
# - not indexed by klass name. Proc would handle the logic for that.
|
11
|
+
# - 3rd, and lowest, priority of scopes
|
12
|
+
# - accepts rails query as parameter
|
13
|
+
# - return nil if no applicable scope.
|
14
|
+
proc_scopes: self::DEFAULT_SCOPE_WRAPPER,
|
15
|
+
# Applied to all queries. Useful for taking advantage of specific indexes
|
16
|
+
# - 2nd highest priority of scopes
|
5
17
|
proc_scopes_per_class_name: {},
|
6
18
|
}.freeze
|
7
19
|
|
8
|
-
# Default Custom Scope for all classes, no effect.
|
9
|
-
DEFAULT_SCOPE_WRAPPER = ->(query) { query }
|
10
20
|
|
11
21
|
# Default Database wrapper, no effect.
|
12
22
|
DEFAULT_DB_WRAPPER = ->(block) { block.call }
|
@@ -27,12 +37,19 @@ module BulkDependencyEraser
|
|
27
37
|
|
28
38
|
protected
|
29
39
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
40
|
+
def custom_scope_for_query(query)
|
41
|
+
klass = query.klass
|
42
|
+
if opts_c.proc_scopes_per_class_name.key?(klass.name)
|
43
|
+
opts_c.proc_scopes_per_class_name[klass.name].call(query)
|
33
44
|
else
|
34
|
-
#
|
35
|
-
|
45
|
+
# See if non-class-mapped proc returns a value
|
46
|
+
non_class_name_mapped_query = opts_c.proc_scopes.call(query)
|
47
|
+
if !non_class_name_mapped_query.nil?
|
48
|
+
return non_class_name_mapped_query
|
49
|
+
else
|
50
|
+
# No custom wrapper, return non-effect default
|
51
|
+
return self.class::DEFAULT_KLASS_MAPPED_SCOPE_WRAPPER.call(query)
|
52
|
+
end
|
36
53
|
end
|
37
54
|
end
|
38
55
|
|
@@ -21,8 +21,16 @@ module BulkDependencyEraser
|
|
21
21
|
# A specific read batching disable option
|
22
22
|
disable_read_batching: nil,
|
23
23
|
# Applied to all queries. Useful for taking advantage of specific indexes
|
24
|
+
# - not indexed by klass name. Proc would handle the logic for that.
|
25
|
+
# - 3rd, and lowest, priority of scopes
|
26
|
+
# - accepts rails query as parameter
|
27
|
+
# - return nil if no applicable scope.
|
28
|
+
proc_scopes: self::DEFAULT_SCOPE_WRAPPER,
|
29
|
+
# Applied to all queries. Useful for taking advantage of specific indexes
|
30
|
+
# - 2nd highest priority of scopes
|
24
31
|
proc_scopes_per_class_name: {},
|
25
|
-
# Applied to
|
32
|
+
# Applied to reading queries
|
33
|
+
# - 1st priority of scopes
|
26
34
|
reading_proc_scopes_per_class_name: {},
|
27
35
|
}.freeze
|
28
36
|
|
@@ -155,11 +163,12 @@ module BulkDependencyEraser
|
|
155
163
|
attr_reader :table_names_to_parsed_klass_names
|
156
164
|
attr_reader :ignore_table_name_and_dependencies, :ignore_klass_name_and_dependencies
|
157
165
|
|
158
|
-
def
|
159
|
-
|
160
|
-
|
166
|
+
def custom_scope_for_query(query)
|
167
|
+
klass = query.klass
|
168
|
+
if opts_c.reading_proc_scopes_per_class_name.key?(klass.name)
|
169
|
+
opts_c.reading_proc_scopes_per_class_name[klass.name].call(query)
|
161
170
|
else
|
162
|
-
super(
|
171
|
+
super(query)
|
163
172
|
end
|
164
173
|
end
|
165
174
|
|
@@ -167,7 +176,7 @@ module BulkDependencyEraser
|
|
167
176
|
# ordering shouldn't matter in these queries, and would slow it down
|
168
177
|
# - we're ignoring default_scope ordering, but assoc-defined ordering would still take effect
|
169
178
|
query = query.reorder('')
|
170
|
-
query =
|
179
|
+
query = custom_scope_for_query(query)
|
171
180
|
|
172
181
|
query_ids = []
|
173
182
|
read_from_db do
|
@@ -631,7 +640,7 @@ module BulkDependencyEraser
|
|
631
640
|
return
|
632
641
|
end
|
633
642
|
|
634
|
-
query =
|
643
|
+
query = custom_scope_for_query(query)
|
635
644
|
|
636
645
|
foreign_ids_by_type = read_from_db do
|
637
646
|
if batching_disabled? || !query.where({}).limit_value.nil?
|
@@ -13,8 +13,16 @@ module BulkDependencyEraser
|
|
13
13
|
# A specific batching size for this class, overrides the batch_size
|
14
14
|
disable_delete_batching: nil,
|
15
15
|
# Applied to all queries. Useful for taking advantage of specific indexes
|
16
|
+
# - not indexed by klass name. Proc would handle the logic for that.
|
17
|
+
# - 3rd, and lowest, priority of scopes
|
18
|
+
# - accepts rails query as parameter
|
19
|
+
# - return nil if no applicable scope.
|
20
|
+
proc_scopes: self::DEFAULT_SCOPE_WRAPPER,
|
21
|
+
# Applied to all queries. Useful for taking advantage of specific indexes
|
22
|
+
# - 2nd highest priority of scopes
|
16
23
|
proc_scopes_per_class_name: {},
|
17
24
|
# Applied to deletion queries
|
25
|
+
# - 1st priority of scopes
|
18
26
|
deletion_proc_scopes_per_class_name: {},
|
19
27
|
}.freeze
|
20
28
|
|
@@ -69,11 +77,12 @@ module BulkDependencyEraser
|
|
69
77
|
|
70
78
|
attr_reader :class_names_and_ids
|
71
79
|
|
72
|
-
def
|
73
|
-
|
74
|
-
|
80
|
+
def custom_scope_for_query(query)
|
81
|
+
klass = query.klass
|
82
|
+
if opts_c.deletion_proc_scopes_per_class_name.key?(klass.name)
|
83
|
+
opts_c.deletion_proc_scopes_per_class_name[klass.name].call(query)
|
75
84
|
else
|
76
|
-
super(
|
85
|
+
super(query)
|
77
86
|
end
|
78
87
|
end
|
79
88
|
|
@@ -88,7 +97,7 @@ module BulkDependencyEraser
|
|
88
97
|
def delete_by_klass_and_ids klass, ids
|
89
98
|
puts "Deleting #{klass.name}'s IDs: #{ids}" if opts_c.verbose
|
90
99
|
query = klass.unscoped
|
91
|
-
query =
|
100
|
+
query = custom_scope_for_query(query)
|
92
101
|
|
93
102
|
if batching_disabled?
|
94
103
|
puts "Deleting without batching" if opts_c.verbose
|
@@ -15,8 +15,16 @@ module BulkDependencyEraser
|
|
15
15
|
# A specific batching size for this class, overrides the batch_size
|
16
16
|
disable_nullify_batching: nil,
|
17
17
|
# Applied to all queries. Useful for taking advantage of specific indexes
|
18
|
+
# - not indexed by klass name. Proc would handle the logic for that.
|
19
|
+
# - 3rd, and lowest, priority of scopes
|
20
|
+
# - accepts rails query as parameter
|
21
|
+
# - return nil if no applicable scope.
|
22
|
+
proc_scopes: self::DEFAULT_SCOPE_WRAPPER,
|
23
|
+
# Applied to all queries. Useful for taking advantage of specific indexes
|
24
|
+
# - 2nd highest priority of scopes
|
18
25
|
proc_scopes_per_class_name: {},
|
19
|
-
# Applied to
|
26
|
+
# Applied to nullification queries
|
27
|
+
# - 1st priority of scopes
|
20
28
|
nullification_proc_scopes_per_class_name: {},
|
21
29
|
}.freeze
|
22
30
|
|
@@ -127,11 +135,12 @@ module BulkDependencyEraser
|
|
127
135
|
|
128
136
|
attr_reader :class_names_columns_and_ids
|
129
137
|
|
130
|
-
def
|
131
|
-
|
132
|
-
|
138
|
+
def custom_scope_for_query(query)
|
139
|
+
klass = query.klass
|
140
|
+
if opts_c.nullification_proc_scopes_per_class_name.key?(klass.name)
|
141
|
+
opts_c.nullification_proc_scopes_per_class_name[klass.name].call(query)
|
133
142
|
else
|
134
|
-
super(
|
143
|
+
super(query)
|
135
144
|
end
|
136
145
|
end
|
137
146
|
|
@@ -145,7 +154,7 @@ module BulkDependencyEraser
|
|
145
154
|
|
146
155
|
def nullify_by_klass_column_and_ids klass, columns, ids
|
147
156
|
query = klass.unscoped
|
148
|
-
query =
|
157
|
+
query = custom_scope_for_query(query)
|
149
158
|
|
150
159
|
nullify_columns = {}
|
151
160
|
# supporting nullification of groups of columns simultaneously
|