2024-04-04 16:28:57 +02:00
|
|
|
class Migrations::BackfillStableIdJob < ApplicationJob
|
|
|
|
queue_as :low_priority
|
|
|
|
|
2024-04-11 11:44:49 +02:00
|
|
|
BATCH = 100_000
|
|
|
|
|
|
|
|
def perform(iteration)
|
2024-04-04 16:28:57 +02:00
|
|
|
sql = "UPDATE champs SET stable_id = t.stable_id, stream = 'main'
|
|
|
|
FROM types_de_champ t
|
|
|
|
WHERE champs.type_de_champ_id = t.id
|
2024-04-11 11:44:49 +02:00
|
|
|
AND champs.id IN (SELECT id FROM champs WHERE champs.stable_id IS NULL LIMIT ?);"
|
|
|
|
query = ActiveRecord::Base.sanitize_sql_array([sql, BATCH])
|
2024-04-04 16:28:57 +02:00
|
|
|
ActiveRecord::Base.connection.execute(query)
|
2024-04-11 11:44:49 +02:00
|
|
|
|
|
|
|
if Champ.exists?(stable_id: nil)
|
|
|
|
Migrations::BackfillStableIdJob.set(wait: 2.seconds).perform_later(iteration + 1)
|
|
|
|
end
|
2024-04-04 16:28:57 +02:00
|
|
|
end
|
|
|
|
end
|