Skip to content

Instantly share code, notes, and snippets.

@juanghurtado
Created June 13, 2011 07:42
Show Gist options
  • Save juanghurtado/1022428 to your computer and use it in GitHub Desktop.
Save juanghurtado/1022428 to your computer and use it in GitHub Desktop.
Sample migration with data update
class CreateUserProfiles < ActiveRecord::Migration
def self.up
create_table :user_profiles do |t|
t.string :locale, :default => :es
t.string :glucose_test_unit, :default => :mgdl
t.string :location
t.references :user
t.timestamps
end
User.all.each do |user|
user.create_user_profile({
:locale => UserProfile::LOCALES.first,
:glucose_test_unit => UserProfile::GLUCOSE_TEST_UNITS.first
}) if user.user_profile.nil?
say "creating user profile for #{user}!" if user.user_profile.nil?
end
end
def self.down
drop_table :user_profiles
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment