#9 Active Storage - migration
This commit is contained in:
parent
d06d536b2f
commit
97e41d8c36
@ -39,26 +39,25 @@ class ActiveStorageMigration < ActiveRecord::Migration[7.0]
|
|||||||
end
|
end
|
||||||
# Process a file
|
# Process a file
|
||||||
disk_filename = File.basename(path)
|
disk_filename = File.basename(path)
|
||||||
|
$stdout.print path
|
||||||
|
found = false
|
||||||
DmsfFileRevision.where(disk_filename: disk_filename)
|
DmsfFileRevision.where(disk_filename: disk_filename)
|
||||||
.order(source_dmsf_file_revision_id: :asc)
|
.order(source_dmsf_file_revision_id: :asc)
|
||||||
.find_each
|
.each
|
||||||
.with_index do |r, i|
|
.with_index do |r, i|
|
||||||
|
found = true
|
||||||
if i.zero?
|
if i.zero?
|
||||||
r.shared_file.attach(
|
r.shared_file.attach io: File.open(path), filename: r.name
|
||||||
io: File.open(path),
|
|
||||||
filename: r.name,
|
|
||||||
content_type: r.content_type || 'application/octet-stream',
|
|
||||||
identify: false
|
|
||||||
)
|
|
||||||
# Remove the original file
|
# Remove the original file
|
||||||
FileUtils.rm path
|
FileUtils.rm path
|
||||||
key = r.file.blob.key
|
key = r.file.blob.key
|
||||||
$stdout.puts "#{path} => #{File.join(key[0..1], key[2..3], key)} (#{r.file.blob.filename})"
|
$stdout.puts " => #{File.join(key[0..1], key[2..3], key)} (#{r.file.blob.filename})"
|
||||||
else
|
else
|
||||||
# The other revisions should have set the source revision
|
# The other revisions should have set the source revision
|
||||||
warn("r#{r.id}.source_dmsf_file_revision_id is null") unless r.source_dmsf_file_revision_id
|
warn("r#{r.id}.source_dmsf_file_revision_id is null") unless r.source_dmsf_file_revision_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
found ? $stdout.print("\n") : $stdout.print(" revision not found, skipped\n")
|
||||||
end
|
end
|
||||||
# Remove columns duplicated in ActiveStorage
|
# Remove columns duplicated in ActiveStorage
|
||||||
remove_column :dmsf_file_revisions, :digest
|
remove_column :dmsf_file_revisions, :digest
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user