]> git.openstreetmap.org Git - rails.git/commitdiff
Add image fingerprints to users
authorTom Hughes <tom@compton.nu>
Sun, 19 Feb 2012 17:34:52 +0000 (17:34 +0000)
committerTom Hughes <tom@compton.nu>
Mon, 20 Feb 2012 11:53:39 +0000 (11:53 +0000)
db/migrate/20120219161649_add_user_image_fingerprint.rb [new file with mode: 0644]

diff --git a/db/migrate/20120219161649_add_user_image_fingerprint.rb b/db/migrate/20120219161649_add_user_image_fingerprint.rb
new file mode 100644 (file)
index 0000000..5c9dd40
--- /dev/null
@@ -0,0 +1,16 @@
+class AddUserImageFingerprint < ActiveRecord::Migration
+  def up
+    add_column :users, :image_fingerprint, :string, :null => true
+
+    User.where("image_file_name IS NOT NULL").find_each do |user|
+      image = user.image
+
+      user.image_fingerprint = image.generate_fingerprint(image)
+      user.save!
+    end
+  end
+
+  def down
+    remove_column :users, :image_fingerprint
+  end
+end