bulk_dependency_eraser 1.4.0 → 1.4.1
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: 5258d3b15269fb6bd51a5f89f949983a3cf48862cc83f26a8f189bbc11e2ae84
|
4
|
+
data.tar.gz: dbab67950500c1037266232592915a3c27f0b54102619092be465ded4a53024d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 351634d20e814264885ddd4746e2fbaa7a8d27c4ab78fda5d3690e21697de51d1fd51c75d2b749e6f9a4727f79e6fa43d571617364df1e44870a55aeb0e88166
|
7
|
+
data.tar.gz: e8e477e1d5139bd4ac38cb3d4e4371b06688b5dc5e000d8a6a6077cc300ec998916cdd754c00d87ea1efd0b0a179479c60491450467cfc8eefbb6b0bda391690
|
@@ -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,18 @@ module BulkDependencyEraser
|
|
27
37
|
|
28
38
|
protected
|
29
39
|
|
30
|
-
def custom_scope_for_klass_name(
|
31
|
-
if opts_c.proc_scopes_per_class_name.key?(
|
32
|
-
opts_c.proc_scopes_per_class_name[
|
40
|
+
def custom_scope_for_klass_name(klass)
|
41
|
+
if opts_c.proc_scopes_per_class_name.key?(klass.name)
|
42
|
+
opts_c.proc_scopes_per_class_name[klass.name]
|
33
43
|
else
|
34
|
-
#
|
35
|
-
|
44
|
+
# See if non-class-mapped proc returns a value
|
45
|
+
non_class_name_mapped_query = opts_c.proc_scopes.call(klass.where({})) # convert klass to query
|
46
|
+
if !non_class_name_mapped_query.nil?
|
47
|
+
return opts_c.proc_scopes
|
48
|
+
else
|
49
|
+
# No custom wrapper, return non-effect default
|
50
|
+
return self.class::DEFAULT_KLASS_MAPPED_SCOPE_WRAPPER
|
51
|
+
end
|
36
52
|
end
|
37
53
|
end
|
38
54
|
|
@@ -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,11 @@ 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 custom_scope_for_klass_name(
|
159
|
-
if opts_c.reading_proc_scopes_per_class_name.key?(
|
160
|
-
opts_c.reading_proc_scopes_per_class_name[
|
166
|
+
def custom_scope_for_klass_name(klass)
|
167
|
+
if opts_c.reading_proc_scopes_per_class_name.key?(klass.name)
|
168
|
+
opts_c.reading_proc_scopes_per_class_name[klass.name]
|
161
169
|
else
|
162
|
-
super(
|
170
|
+
super(klass)
|
163
171
|
end
|
164
172
|
end
|
165
173
|
|
@@ -167,7 +175,7 @@ module BulkDependencyEraser
|
|
167
175
|
# ordering shouldn't matter in these queries, and would slow it down
|
168
176
|
# - we're ignoring default_scope ordering, but assoc-defined ordering would still take effect
|
169
177
|
query = query.reorder('')
|
170
|
-
query = custom_scope_for_klass_name(query.klass
|
178
|
+
query = custom_scope_for_klass_name(query.klass).call(query)
|
171
179
|
|
172
180
|
query_ids = []
|
173
181
|
read_from_db do
|
@@ -631,7 +639,7 @@ module BulkDependencyEraser
|
|
631
639
|
return
|
632
640
|
end
|
633
641
|
|
634
|
-
query = custom_scope_for_klass_name(query.klass
|
642
|
+
query = custom_scope_for_klass_name(query.klass).call(query)
|
635
643
|
|
636
644
|
foreign_ids_by_type = read_from_db do
|
637
645
|
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,11 @@ module BulkDependencyEraser
|
|
69
77
|
|
70
78
|
attr_reader :class_names_and_ids
|
71
79
|
|
72
|
-
def custom_scope_for_klass_name(
|
73
|
-
if opts_c.deletion_proc_scopes_per_class_name.key?(
|
74
|
-
opts_c.deletion_proc_scopes_per_class_name[
|
80
|
+
def custom_scope_for_klass_name(klass)
|
81
|
+
if opts_c.deletion_proc_scopes_per_class_name.key?(klass.name)
|
82
|
+
opts_c.deletion_proc_scopes_per_class_name[klass.name]
|
75
83
|
else
|
76
|
-
super(
|
84
|
+
super(klass)
|
77
85
|
end
|
78
86
|
end
|
79
87
|
|
@@ -88,7 +96,7 @@ module BulkDependencyEraser
|
|
88
96
|
def delete_by_klass_and_ids klass, ids
|
89
97
|
puts "Deleting #{klass.name}'s IDs: #{ids}" if opts_c.verbose
|
90
98
|
query = klass.unscoped
|
91
|
-
query = custom_scope_for_klass_name(klass
|
99
|
+
query = custom_scope_for_klass_name(klass).call(query)
|
92
100
|
|
93
101
|
if batching_disabled?
|
94
102
|
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,11 @@ module BulkDependencyEraser
|
|
127
135
|
|
128
136
|
attr_reader :class_names_columns_and_ids
|
129
137
|
|
130
|
-
def custom_scope_for_klass_name(
|
131
|
-
if opts_c.nullification_proc_scopes_per_class_name.key?(
|
132
|
-
opts_c.nullification_proc_scopes_per_class_name[
|
138
|
+
def custom_scope_for_klass_name(klass)
|
139
|
+
if opts_c.nullification_proc_scopes_per_class_name.key?(klass.name)
|
140
|
+
opts_c.nullification_proc_scopes_per_class_name[klass.name]
|
133
141
|
else
|
134
|
-
super(
|
142
|
+
super(klass)
|
135
143
|
end
|
136
144
|
end
|
137
145
|
|
@@ -145,7 +153,7 @@ module BulkDependencyEraser
|
|
145
153
|
|
146
154
|
def nullify_by_klass_column_and_ids klass, columns, ids
|
147
155
|
query = klass.unscoped
|
148
|
-
query = custom_scope_for_klass_name(klass
|
156
|
+
query = custom_scope_for_klass_name(klass).call(query)
|
149
157
|
|
150
158
|
nullify_columns = {}
|
151
159
|
# supporting nullification of groups of columns simultaneously
|