bulk_dependency_eraser 1.5.0 → 2.0.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: a7d8f49a22e2103cef90bfb21c415d0dd687040cf31961d199ff5041d942de68
|
4
|
+
data.tar.gz: 5d264a97b2a00f479c13d8f69a2b00218464700465b2f8cf6f7703d37742b4a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdfe1a03baab1a7d0bbd1a6984723815790dca786564df1cdf322ace227fc4734db60ae5c11d42d0b0d1f9f507fc6483091b42a641927acfe12cd87b5cf5eedb
|
7
|
+
data.tar.gz: 1c80246cc7315d5250fdbf0aa75fb199f0b1cdedd510282e45885e476caaff5ecee2896ef12a5053060858a300d860cb1ac2ace462907d0a021efed7dfa7cc9f
|
@@ -94,27 +94,6 @@ module BulkDependencyEraser
|
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
# Reverse order IDs
|
98
|
-
# - if a class self-referenced itself the children will be deleted/nullified before parent
|
99
|
-
deletion_list.keys.each do |class_name|
|
100
|
-
deletion_list[class_name] = deletion_list.delete(class_name).reverse
|
101
|
-
|
102
|
-
# TODO: Hard to test if not sorted
|
103
|
-
deletion_list[class_name] = deletion_list[class_name].sort if Rails.env.test?
|
104
|
-
end
|
105
|
-
|
106
|
-
nullification_list.keys.each do |class_name|
|
107
|
-
columns_and_ids = nullification_list.delete(class_name)
|
108
|
-
# we don't need to reverse the column keys
|
109
|
-
columns_and_ids.keys.each do |column_name|
|
110
|
-
columns_and_ids[column_name] = columns_and_ids.delete(column_name).reverse
|
111
|
-
|
112
|
-
# TODO: Hard to test if not sorted
|
113
|
-
columns_and_ids[column_name] = columns_and_ids.delete(column_name).sort if Rails.env.test?
|
114
|
-
end
|
115
|
-
nullification_list[class_name] = columns_and_ids
|
116
|
-
end
|
117
|
-
|
118
97
|
return build_result
|
119
98
|
end
|
120
99
|
|
@@ -36,32 +36,29 @@ module BulkDependencyEraser
|
|
36
36
|
puts "ActiveRecord::Base.connection.disable_referential_integrity - disabled!"
|
37
37
|
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
klass = class_name.constantize
|
39
|
+
current_class_name = 'N/A'
|
40
|
+
begin
|
41
|
+
# IDs should have already been reversed in builder
|
42
|
+
class_names_and_ids.keys.reverse.each do |class_name|
|
43
|
+
current_class_name = class_name
|
44
|
+
ids = class_names_and_ids[class_name].reverse
|
45
|
+
klass = class_name.constantize
|
47
46
|
|
48
|
-
|
49
|
-
|
47
|
+
if opts_c.enable_invalid_foreign_key_detection
|
48
|
+
# delete with referential integrity
|
49
|
+
delete_by_klass_and_ids(klass, ids)
|
50
|
+
else
|
51
|
+
# delete without referential integrity
|
52
|
+
# Disable any ActiveRecord::InvalidForeignKey raised errors.
|
53
|
+
# - src: https://stackoverflow.com/questions/41005849/rails-migrations-temporarily-ignore-foreign-key-constraint
|
54
|
+
# https://apidock.com/rails/ActiveRecord/ConnectionAdapters/AbstractAdapter/disable_referential_integrity
|
55
|
+
ActiveRecord::Base.connection.disable_referential_integrity do
|
50
56
|
delete_by_klass_and_ids(klass, ids)
|
51
|
-
else
|
52
|
-
# delete without referential integrity
|
53
|
-
# Disable any ActiveRecord::InvalidForeignKey raised errors.
|
54
|
-
# - src: https://stackoverflow.com/questions/41005849/rails-migrations-temporarily-ignore-foreign-key-constraint
|
55
|
-
# https://apidock.com/rails/ActiveRecord/ConnectionAdapters/AbstractAdapter/disable_referential_integrity
|
56
|
-
ActiveRecord::Base.connection.disable_referential_integrity do
|
57
|
-
delete_by_klass_and_ids(klass, ids)
|
58
|
-
end
|
59
57
|
end
|
60
58
|
end
|
61
|
-
rescue StandardError => e
|
62
|
-
report_error("Issue attempting to delete '#{current_class_name}': #{e.class.name} - #{e.message}")
|
63
|
-
raise ActiveRecord::Rollback
|
64
59
|
end
|
60
|
+
rescue StandardError => e
|
61
|
+
report_error("Issue attempting to delete '#{current_class_name}': #{e.class.name} - #{e.message}")
|
65
62
|
end
|
66
63
|
|
67
64
|
return errors.none?
|
@@ -89,37 +89,36 @@ module BulkDependencyEraser
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def execute
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
92
|
+
current_class_name = 'N/A'
|
93
|
+
current_column = 'N/A'
|
94
|
+
begin
|
95
|
+
# column_and_ids should have already been reversed in builder
|
96
|
+
class_names_columns_and_ids.keys.reverse.each do |class_name|
|
97
|
+
current_class_name = class_name
|
98
|
+
klass = class_name.constantize
|
99
|
+
columns_and_ids = class_names_columns_and_ids[class_name]
|
100
|
+
|
101
|
+
columns_and_ids.each do |column, ids|
|
102
|
+
current_column = column
|
103
|
+
# Reversing IDs. Last ones in are more likely to be dependencies, and should be deleted first.
|
104
|
+
ids = ids.reverse
|
105
|
+
|
106
|
+
if opts_c.enable_invalid_foreign_key_detection
|
107
|
+
# nullify with referential integrity
|
108
|
+
nullify_by_klass_column_and_ids(klass, column, ids)
|
109
|
+
else
|
110
|
+
# nullify without referential integrity
|
111
|
+
# Disable any ActiveRecord::InvalidForeignKey raised errors.
|
112
|
+
# - src: https://stackoverflow.com/questions/41005849/rails-migrations-temporarily-ignore-foreign-key-constraint
|
113
|
+
# https://apidock.com/rails/ActiveRecord/ConnectionAdapters/AbstractAdapter/disable_referential_integrity
|
114
|
+
ActiveRecord::Base.connection.disable_referential_integrity do
|
107
115
|
nullify_by_klass_column_and_ids(klass, column, ids)
|
108
|
-
else
|
109
|
-
# nullify without referential integrity
|
110
|
-
# Disable any ActiveRecord::InvalidForeignKey raised errors.
|
111
|
-
# - src: https://stackoverflow.com/questions/41005849/rails-migrations-temporarily-ignore-foreign-key-constraint
|
112
|
-
# https://apidock.com/rails/ActiveRecord/ConnectionAdapters/AbstractAdapter/disable_referential_integrity
|
113
|
-
ActiveRecord::Base.connection.disable_referential_integrity do
|
114
|
-
nullify_by_klass_column_and_ids(klass, column, ids)
|
115
|
-
end
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
119
|
-
rescue StandardError => e
|
120
|
-
report_error("Issue attempting to nullify '#{current_class_name}' column '#{current_column}': #{e.class.name} - #{e.message}")
|
121
|
-
raise ActiveRecord::Rollback
|
122
119
|
end
|
120
|
+
rescue StandardError => e
|
121
|
+
report_error("Issue attempting to nullify '#{current_class_name}' column '#{current_column}': #{e.class.name} - #{e.message}")
|
123
122
|
end
|
124
123
|
|
125
124
|
return errors.none?
|