Class: Upgrade::ConvertSupportedRelationshipsJob

Inherits:
IterationJob
  • Object
show all
Defined in:
app/jobs/upgrade/convert_supported_relationships_job.rb

Instance Method Summary collapse

Instance Method Details

#build_enumerator(cursor:) ⇒ Object



6
7
8
9
# File 'app/jobs/upgrade/convert_supported_relationships_job.rb', line 6

def build_enumerator(cursor:)
  # Find models that have something in the old presupported version field
  enumerator_builder.active_record_on_records(ModelFile.where.not(presupported_version_id: nil), cursor: cursor)
end

#each_iteration(record) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'app/jobs/upgrade/convert_supported_relationships_job.rb', line 11

def each_iteration(record)
  record.reverse_relationships.find_or_create_by(
    subject_type: "ModelFile",
    subject_id: record.presupported_version_id,
    predicate: "supported_version_of"
  )
  # Remove the old collection ID without validation, callbacks, or touching the date
  record.update_column :presupported_version_id, nil # rubocop:disable Rails/SkipsModelValidations
end