Fixed migration.

This commit is contained in:
Martin Edenhofer 2014-05-03 21:02:38 +02:00
parent 84c23e2311
commit 0a726148c7
3 changed files with 15 additions and 3 deletions

View file

@ -29,7 +29,13 @@ class Store::File < ApplicationModel
# read content # read content
def content def content
adapter = self.class.load_adapter("Store::Provider::#{ self.provider }") 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 end
# check data and sha, in case fix it # check data and sha, in case fix it

View file

@ -22,7 +22,7 @@ class Store::Provider::File
# generate directory # generate directory
base = Rails.root.to_s + '/storage/fs/' base = Rails.root.to_s + '/storage/fs/'
parts = sha.scan(/.{1,3}/) parts = sha.scan(/.{1,4}/)
path = parts[ 1 .. 10 ].join('/') + '/' path = parts[ 1 .. 10 ].join('/') + '/'
file = parts[ 11 .. parts.count ].join('') file = parts[ 11 .. parts.count ].join('')
location = "#{base}/#{path}" location = "#{base}/#{path}"

View file

@ -12,12 +12,18 @@ class UpdateStorage3 < ActiveRecord::Migration
sha = Digest::SHA256.hexdigest( file.content ) sha = Digest::SHA256.hexdigest( file.content )
file.update_attribute( :sha, sha ) file.update_attribute( :sha, sha )
} }
Store::Provider::DB.all.each {|file| Store::File.all.each {|file|
next if file.sha next if file.sha
sha = Digest::SHA256.hexdigest( file.content ) sha = Digest::SHA256.hexdigest( file.content )
file.update_attribute( :sha, sha ) 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_files, :md5
remove_column :store_provider_dbs, :md5 remove_column :store_provider_dbs, :md5
end end