bulk_dependency_eraser 4.4.0 → 4.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: dcd62dc450607a490d23f589f457c2e2ad30b6ba4096b775266372d2f3952445
4
- data.tar.gz: 8e430d8e74cf2d401b75d335a7fc3da82672aa4fedbc0446024bf94c1f632116
3
+ metadata.gz: 886ff4e4e736393ca417bfca554cc0f0cac8dd3d2c78233e8cfdb9c007d4b0f1
4
+ data.tar.gz: d81c392e904f999442287d77349b52659dd14621da208ce5f942ff8f4529e5a3
5
5
  SHA512:
6
- metadata.gz: f9added303e9a0982bd9cc026ef03937e0c095421fe89ba7edbdf24c7af27af61cce2f1e3c84b8f56d79fbf441ab5a4d72362fe9053b536af0286cb917c1abbc
7
- data.tar.gz: 794831e885f3659586f5ffd075e93aee67d15e919bc2915023e733460e8739d4e5d7f86079f23feaf1cecb0a4a9ffaa6be5ccf885376203464fa7641952413c7
6
+ metadata.gz: e0d7a0e10751d57d39dfc99ed6639170af4484f228b9778b8a7187c2168004738c1faf538c5417cf0037862a48635937723677367226816291696f20fad0eaae
7
+ data.tar.gz: edbefd2f654115b2566ad2b1c5b38fb6ca2970a61f0c7371e9254896c6a34c6c81044020a5fc4ac32d6bf4199c96858e059c1ed2c16578ceac3ac0383ec09901
@@ -146,30 +146,19 @@ module BulkDependencyEraser
146
146
  detected_additional_identifier_columns = additional_identifiers&.values&.flat_map(&:keys)&.uniq || []
147
147
 
148
148
  if opts_c.use_pg_system_column_ctid && opts_c.delete_ctids_by_partions && (detected_additional_identifier_columns & ['ctid', 'tableoid::regclass']).size == 2
149
- partioned_tables = additional_identifiers.values.pluck('tableoid::regclass').uniq
149
+ deletable_partioned_tables_by_ctids = additional_identifiers.values.pluck('tableoid::regclass').uniq
150
150
  end
151
151
 
152
152
  if batching_disabled?
153
153
  puts "Deleting without batching" if opts_c.verbose
154
154
  # Delete by partioned CTIDs
155
- if opts_c.use_pg_system_column_ctid && opts_c.delete_ctids_by_partions && (detected_additional_identifier_columns & ['ctid', 'tableoid::regclass']).size == 2
155
+ if deletable_partioned_tables_by_ctids
156
156
  puts "Deleting via CTID and table partitions" if opts_c.verbose
157
- partioned_tables.each do |table_partition|
157
+ deletable_partioned_tables_by_ctids.each do |table_partition|
158
158
  identifiers_by_partition = additional_identifiers.filter { |id, identifiers| identifiers['tableoid::regclass'] == table_partition }
159
159
  ctids = identifiers_by_partition.values.pluck('ctid')
160
- delete_in_db do
161
- sql = <<~SQL
162
- DELETE FROM #{table_partition}
163
- WHERE ctid IN (#{ctids.map { |c| "'#{c}'" }.join(', ')});
164
- SQL
165
- # Due to the way we've mocked/aliased the partition table in this gem test, we need to also add the partition name as a where clause.
166
- if ENV['TEST_GEM_ENV'] == 'bulk_dependency_eraser'
167
- sql.sub!(/;\s*$/, "") # remove terminating semicolon
168
- sql << " AND tableoid = '#{table_partition}';"
169
- end
170
- deleted_count = klass.connection.delete(sql)
171
- [deleted_count, sql, identifiers_by_partition.keys, identifiers_by_partition]
172
- end
160
+ ids = identifiers_by_partition.values.pluck('id')
161
+ deletion_by_partitioned_ctids(query, ids, ctids, table_partition, identifiers_by_partition)
173
162
  end
174
163
  else
175
164
  delete_in_db do
@@ -195,29 +184,15 @@ module BulkDependencyEraser
195
184
  end
196
185
  else
197
186
  puts "Deleting with batching" if opts_c.verbose
198
- if opts_c.use_pg_system_column_ctid && opts_c.delete_ctids_by_partions && (detected_additional_identifier_columns & ['ctid', 'tableoid::regclass']).size == 2
187
+ if deletable_partioned_tables_by_ctids
199
188
  puts "Deleting via CTID and table partitions" if opts_c.verbose
200
- partioned_tables.each do |table_partition|
189
+ deletable_partioned_tables_by_ctids.each do |table_partition|
201
190
  identifiers_by_partition = additional_identifiers.filter { |id, identifiers| identifiers['tableoid::regclass'] == table_partition }
202
191
  ids = identifiers_by_partition.keys
203
192
  ids.each_slice(batch_size) do |ids_subset|
204
193
  additional_identifiers_subset = identifiers_by_partition.slice(*ids_subset)
205
194
  ctids = additional_identifiers_subset.values.pluck('ctid')
206
- delete_in_db do
207
- sql = <<~SQL
208
- DELETE FROM #{table_partition}
209
- WHERE ctid IN (#{ctids.map { |c| "'#{c}'" }.join(', ')});
210
- SQL
211
-
212
- # Due to the way we've mocked/aliased the partition table in this gem test, we need to also add the partition name as a where clause.
213
- if ENV['TEST_GEM_ENV'] == 'bulk_dependency_eraser'
214
- sql.sub!(/;\s*$/, "") # remove terminating semicolon
215
- sql << " AND tableoid = '#{table_partition}';"
216
- end
217
-
218
- deleted_count = klass.connection.delete(sql)
219
- [deleted_count, sql, ids_subset, additional_identifiers_subset]
220
- end
195
+ deletion_by_partitioned_ctids(query, ids_subset, ctids, table_partition, identifiers_by_partition)
221
196
  end
222
197
  end
223
198
  else
@@ -251,6 +226,29 @@ module BulkDependencyEraser
251
226
  end
252
227
  end
253
228
 
229
+ def deletion_by_partitioned_ctids query, ids, ctids, partition_table_name, additional_identifiers
230
+ delete_in_db do
231
+ where_clause_sql = <<~SQL
232
+ ctid IN (#{ctids.map { |c| "'#{c}'" }.join(', ')})
233
+ SQL
234
+
235
+ deletion_sql = <<~SQL
236
+ DELETE FROM #{partition_table_name}
237
+ WHERE #{where_clause_sql};
238
+ SQL
239
+
240
+ # Due to the way we've mocked/aliased the partition table in this gem test, we need to also add the partition name as a where clause.
241
+ if ENV['TEST_GEM_ENV'] == 'bulk_dependency_eraser'
242
+ deletion_sql.sub!(/;\s*$/, "") # remove terminating semicolon
243
+ deletion_sql << " AND tableoid = '#{partition_table_name}';"
244
+ end
245
+
246
+ deleted_count = query.klass.connection.delete(deletion_sql)
247
+ selector_query = query.where(Arel.sql(where_clause_sql))
248
+ [deleted_count, selector_query, ids, additional_identifiers]
249
+ end
250
+ end
251
+
254
252
  def delete_in_db(&block)
255
253
  puts "Deleting from DB..." if opts_c.verbose
256
254
  opts_c.db_delete_wrapper.call(block)
@@ -1,3 +1,3 @@
1
1
  module BulkDependencyEraser
2
- VERSION = "4.4.0".freeze
2
+ VERSION = "4.4.1".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bulk_dependency_eraser
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.0
4
+ version: 4.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - benjamin.dana.software.dev@gmail.com