Modified: branches/showcase48/Rakefile (3011 => 3012)
--- branches/showcase48/Rakefile 2012-05-30 11:04:38 UTC (rev 3011)
+++ branches/showcase48/Rakefile 2012-06-05 10:17:13 UTC (rev 3012)
@@ -192,3 +192,14 @@
puts doc.to_s
end
+desc 'Rebuild checksums in the content blob store'
+task "myexp:blobstore:checksum:rebuild" do
+ require File.dirname(__FILE__) + '/config/environment'
+
+ ContentBlob.all.each do |blob|
+ blob.update_checksums
+ puts "blob changed? = #{blob.changed?}"
+ blob.save if blob.changed?
+ end
+end
+
Modified: branches/showcase48/app/models/content_blob.rb (3011 => 3012)
--- branches/showcase48/app/models/content_blob.rb 2012-05-30 11:04:38 UTC (rev 3011)
+++ branches/showcase48/app/models/content_blob.rb 2012-06-05 10:17:13 UTC (rev 3012)
@@ -3,6 +3,19 @@
# Copyright (c) 2009 University of Manchester and the University of Southampton.
# See license.txt for details.
+require 'digest/md5'
+require 'digest/sha1'
+
class ContentBlob < ActiveRecord::Base
validates_presence_of :data
+
+ before_save do |blob|
+ blob.update_checksums
+ end
+
+ def update_checksums
+ self.md5 = Digest::MD5.hexdigest(data)
+ self.sha1 = Digest::SHA1.hexdigest(data)
+ end
+
end
Added: branches/showcase48/db/migrate/20120605091404_add_checksums_to_content_blobs.rb (0 => 3012)
--- branches/showcase48/db/migrate/20120605091404_add_checksums_to_content_blobs.rb (rev 0)
+++ branches/showcase48/db/migrate/20120605091404_add_checksums_to_content_blobs.rb 2012-06-05 10:17:13 UTC (rev 3012)
@@ -0,0 +1,16 @@
+# myExperiment: db/migrate/20120605091404_add_checksums_to_content_blobs.rb
+#
+# Copyright (c) 2012 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class AddChecksumsToContentBlobs < ActiveRecord::Migration
+ def self.up
+ add_column :content_blobs, :md5, :string, :limit => 32
+ add_column :content_blobs, :sha1, :string, :limit => 40
+ end
+
+ def self.down
+ remove_column :content_blobs, :md5
+ remove_column :content_blobs, :sha1
+ end
+end