blob: 01d6d068ca4ffacb6db0be340b585dd59ba6378d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# frozen_string_literal: true
class LooseForeignKeys::DeletedRecord < ApplicationRecord
self.primary_key = :id
scope :for_table, -> (table) { where(fully_qualified_table_name: table) }
scope :ordered_by_id, -> { order(:id, :primary_key_value) }
# This needs to be parameterized once we start adding partitions
scope :for_partition, -> { where(partition: 1) }
enum status: { pending: 1, processed: 2 }, _prefix: :status
def self.load_batch_for_table(table, batch_size)
for_table(table)
.for_partition
.status_pending
.ordered_by_id
.limit(batch_size)
.to_a
end
def self.mark_records_processed_for_table_between(table, from_record, to_record)
from = from_record.id
to = to_record.id
for_table(table)
.for_partition
.status_pending
.where(id: from..to)
.update_all(status: :processed)
end
end
|