cirandas.net

ref: master

db/migrate/079_fix_people_without_names.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
class FixPeopleWithoutNames < ActiveRecord::Migration
  def self.up
    select_all("SELECT name, identifier FROM profiles WHERE name = '' or name IS NULL").each do |profile|
      update("UPDATE profiles SET name = '%s' WHERE identifier = '%s'" % [profile['identifier'], profile['identifier']])
    end
  end

  def self.down
    say("Nothing to undo (cannot recover the data)")
  end
end