Skip to content

Commit

Permalink
Merge pull request #2986 from manyfold3d/another-migration-fix
Browse files Browse the repository at this point in the history
Skip validations while attaching files in migration
  • Loading branch information
Floppy authored Oct 18, 2024
2 parents 51c3cbe + 62bdfbf commit e61d96f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/models/model_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def path_within_library
File.join(model.path, filename)
end

def attach_existing_file!(refresh: true)
def attach_existing_file!(refresh: true, skip_validations: false)
return if attachment.present? || !exists_on_storage?
attachment_attacher.set LibraryUploader.uploaded_file(
storage: model.library.storage_key,
Expand All @@ -96,7 +96,7 @@ def attach_existing_file!(refresh: true)
}
)
attachment_attacher.refresh_metadata! if refresh
save!
save!(validate: !skip_validations)
end

def exists_on_storage?
Expand Down
2 changes: 1 addition & 1 deletion db/data/20240615085913_move_file_data_into_shrine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class MoveFileDataIntoShrine < ActiveRecord::Migration[7.0]
def up
ModelFile.find_each { |x| x.attach_existing_file!(refresh: false) }
ModelFile.find_each { |x| x.attach_existing_file!(refresh: false, skip_validations: true) }
end

def down
Expand Down

0 comments on commit e61d96f

Please sign in to comment.