Created
June 13, 2011 07:42
-
-
Save juanghurtado/1022428 to your computer and use it in GitHub Desktop.
Sample migration with data update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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