From 0a726148c71318c29bbbca9a86b47e4591b41297 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 3 May 2014 21:02:38 +0200 Subject: [PATCH] Fixed migration. --- app/models/store/file.rb | 8 +++++++- app/models/store/provider/file.rb | 2 +- db/migrate/20140503000001_update_storage3.rb | 8 +++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/models/store/file.rb b/app/models/store/file.rb index bc9b6c6a2..ef7313300 100644 --- a/app/models/store/file.rb +++ b/app/models/store/file.rb @@ -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 diff --git a/app/models/store/provider/file.rb b/app/models/store/provider/file.rb index 35c2c98c7..9bd54dde2 100644 --- a/app/models/store/provider/file.rb +++ b/app/models/store/provider/file.rb @@ -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}" diff --git a/db/migrate/20140503000001_update_storage3.rb b/db/migrate/20140503000001_update_storage3.rb index 9f5e5263e..35461e874 100644 --- a/db/migrate/20140503000001_update_storage3.rb +++ b/db/migrate/20140503000001_update_storage3.rb @@ -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