Diff
Modified: trunk/Rakefile (3138 => 3139)
--- trunk/Rakefile 2012-09-27 14:01:57 UTC (rev 3138)
+++ trunk/Rakefile 2012-09-27 16:36:18 UTC (rev 3139)
@@ -223,3 +223,12 @@
end
end
+desc 'Rebuild checksums in the content blob store'
+task "myexp:blobstore:checksum:rebuild" do
+ require File.dirname(__FILE__) + '/config/environment'
+
+ conn = ActiveRecord::Base.connection
+
+ conn.execute('UPDATE content_blobs SET sha1 = SHA1(data), md5 = MD5(data)')
+end
+
Modified: trunk/app/models/content_blob.rb (3138 => 3139)
--- trunk/app/models/content_blob.rb 2012-09-27 14:01:57 UTC (rev 3138)
+++ trunk/app/models/content_blob.rb 2012-09-27 16:36:18 UTC (rev 3139)
@@ -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: trunk/db/migrate/097_add_checksums_to_content_blobs.rb (0 => 3139)
--- trunk/db/migrate/097_add_checksums_to_content_blobs.rb (rev 0)
+++ trunk/db/migrate/097_add_checksums_to_content_blobs.rb 2012-09-27 16:36:18 UTC (rev 3139)
@@ -0,0 +1,19 @@
+# myExperiment: db/migrate/097_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
+
+ add_index :content_blobs, :md5
+ add_index :content_blobs, :sha1
+ end
+
+ def self.down
+ remove_column :content_blobs, :md5
+ remove_column :content_blobs, :sha1
+ end
+end
Modified: trunk/db/schema.rb (3138 => 3139)
--- trunk/db/schema.rb 2012-09-27 14:01:57 UTC (rev 3138)
+++ trunk/db/schema.rb 2012-09-27 16:36:18 UTC (rev 3139)
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 96) do
+ActiveRecord::Schema.define(:version => 97) do
create_table "activity_limits", :force => true do |t|
t.string "contributor_type", :null => false
@@ -160,8 +160,13 @@
create_table "content_blobs", :force => true do |t|
t.binary "data", :limit => 2147483647
+ t.string "md5", :limit => 32
+ t.string "sha1", :limit => 40
end
+ add_index "content_blobs", ["md5"], :name => "index_content_blobs_on_md5"
+ add_index "content_blobs", ["sha1"], :name => "index_content_blobs_on_sha1"
+
create_table "content_types", :force => true do |t|
t.integer "user_id"
t.string "title"