Module: SaveNullifiedRelsToFile

Includes:
SaveFile
Included in:
Backup::RemoveOrphans, Backup::RemoveSpecified::RemoveHeavyData, Backup::RemoveSpecified::RemoveWithAllDependencies
Defined in:
lib/backup/save_nullified_rels_to_file.rb

Instance Method Summary collapse

Methods included from SaveFile

#current_time_for_subfolder, #ensure_path, #folder_path, #full_file_path, #save_file

Instance Method Details

#save_nullified_rels_to_file(rels_hash) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/backup/save_nullified_rels_to_file.rb', line 6

def save_nullified_rels_to_file(rels_hash)
  @file_index = 1

  rels_hash.each do |name, rels|
    rels&.compact&.each_slice(@config.limit.to_i) do |rels_batch|
      save_rels_batch_to_file(name, rels_batch)
    end
  end
end

#save_rels_batch_to_file(name, rels_batch) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/backup/save_nullified_rels_to_file.rb', line 16

def save_rels_batch_to_file(name, rels_batch)
  model = Model.get_model(name)

  export = {}
  export[:table_name] = model.table_name
  export[:nullified_relationships] = rels_batch

  content = JSON.pretty_generate(export)
  file_name = "nullified_relationships/build_#{@file_index}.json"
  @file_index += 1
  file_path = @subfolder.present? ? "#{@subfolder}/#{file_name}" : file_name
  save_file(file_path, content)
end