Class: Upgrade::FixStaleAttachmentDataJob

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

Instance Method Summary collapse

Instance Method Details

#build_enumerator(cursor:) ⇒ Object



18
19
20
# File 'app/jobs/upgrade/fix_stale_attachment_data_job.rb', line 18

def build_enumerator(cursor:)
  enumerator_builder.active_record_on_records(scope, cursor: cursor)
end

#each_iteration(modelfile) ⇒ Object



22
23
24
25
26
# File 'app/jobs/upgrade/fix_stale_attachment_data_job.rb', line 22

def each_iteration(modelfile)
  modelfile.attachment_data.store("id", modelfile.path_within_library)
  modelfile.attachment_data.store("storage", modelfile.model.library.storage_key.to_s)
  modelfile.save!
end

#scope ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/jobs/upgrade/fix_stale_attachment_data_job.rb', line 4

def scope
  where_clause = case DatabaseDetector.server
  when :postgresql
    "json_extract_path_text(attachment_data, 'storage') = 'cache'"
  when :mysql
    "json_value(attachment_data, '$.storage') = 'cache'"
  when :sqlite
    "json_extract(attachment_data, '$.storage') = 'cache'"
  else
    raise NotImplementedError.new("Unknown database adapter #{DatabaseDetector.server}")
  end
  ModelFile.unscoped.where(where_clause)
end