Browse Source

Fixed migration.

Martin Edenhofer 11 years ago
parent
commit
0a726148c7

+ 7 - 1
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

+ 1 - 1
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}"

+ 7 - 1
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