Fixed migration.
This commit is contained in:
parent
84c23e2311
commit
0a726148c7
3 changed files with 15 additions and 3 deletions
|
@ -29,7 +29,13 @@ class Store::File < ApplicationModel
|
|||
# read content
|
||||
def content
|
||||
adapter = self.class.load_adapter("Store::Provider::#{ self.provider }")
|
||||
adapter.get( self.sha )
|
||||
if self.sha
|
||||
c = adapter.get( self.sha )
|
||||
else
|
||||
# fallback until migration is done
|
||||
c = Store::Provider::DB.where( :md5 => self.md5 ).first.data
|
||||
end
|
||||
c
|
||||
end
|
||||
|
||||
# check data and sha, in case fix it
|
||||
|
|
|
@ -22,7 +22,7 @@ class Store::Provider::File
|
|||
|
||||
# generate directory
|
||||
base = Rails.root.to_s + '/storage/fs/'
|
||||
parts = sha.scan(/.{1,3}/)
|
||||
parts = sha.scan(/.{1,4}/)
|
||||
path = parts[ 1 .. 10 ].join('/') + '/'
|
||||
file = parts[ 11 .. parts.count ].join('')
|
||||
location = "#{base}/#{path}"
|
||||
|
|
|
@ -12,12 +12,18 @@ class UpdateStorage3 < ActiveRecord::Migration
|
|||
sha = Digest::SHA256.hexdigest( file.content )
|
||||
file.update_attribute( :sha, sha )
|
||||
}
|
||||
Store::Provider::DB.all.each {|file|
|
||||
Store::File.all.each {|file|
|
||||
next if file.sha
|
||||
sha = Digest::SHA256.hexdigest( file.content )
|
||||
file.update_attribute( :sha, sha )
|
||||
}
|
||||
|
||||
Store::Provider::DB.all.each {|file|
|
||||
next if file.sha
|
||||
sha = Digest::SHA256.hexdigest( file.data )
|
||||
file.update_attribute( :sha, sha )
|
||||
}
|
||||
|
||||
remove_column :store_files, :md5
|
||||
remove_column :store_provider_dbs, :md5
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue