openstreetmap-website/db/migrate/20120219161649_add_user_image_fingerprint.rb
Andy Allan 6ebb21b660 Avoid using live models in old migrations
Instead, we define models in the migrations themselves. This ensures that
column names etc match the state of the database during the migration,
not the current live version of the model.
2019-07-17 11:52:02 +02:00

19 lines
433 B
Ruby

class AddUserImageFingerprint < ActiveRecord::Migration[4.2]
class User < ActiveRecord::Base
end
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