2024-04-04 16:28:57 +02:00
|
|
|
class Migrations::BackfillStableIdJob < ApplicationJob
|
|
|
|
queue_as :low_priority
|
|
|
|
|
2024-04-15 10:43:39 +02:00
|
|
|
DEFAULT_LIMIT = 50_000
|
2024-04-11 11:44:49 +02:00
|
|
|
|
2024-04-15 10:43:39 +02:00
|
|
|
def perform(iteration, limit = DEFAULT_LIMIT)
|
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 ?);"
|
2024-04-15 10:43:39 +02:00
|
|
|
query = ActiveRecord::Base.sanitize_sql_array([sql, limit])
|
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)
|
2024-04-15 10:43:39 +02:00
|
|
|
Migrations::BackfillStableIdJob.set(wait: 2.seconds).perform_later(iteration + 1, limit)
|
2024-04-11 11:44:49 +02:00
|
|
|
end
|
2024-04-04 16:28:57 +02:00
|
|
|
end
|
|
|
|
end
|