Created
June 27, 2011 21:58
-
-
Save 8th-Light-Blog/1049961 to your computer and use it in GitHub Desktop.
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
Blog Title: Fast-Talking ActiveRecord Migrations | |
Author: Craig Demyanovich | |
Date: May 6th, 2011 |
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 AddApplicationToCe < ActiveRecord::Migration | |
def self.up | |
add_column :continuing_educations, :origin_application, :string | |
ContinuingEducation.find_each do |ce| | |
ce.update_attribute(:origin_application, "bank") | |
end | |
end | |
def self.down | |
remove_column :continuing_educations, :origin_application | |
end | |
end |
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
== AddApplicationToCe: migrating ============================================= | |
-- add_column(:continuing_educations, :origin_application, :string) | |
-> 2.9832s | |
== AddApplicationToCe: migrated (724.5134s) ================================== |
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 AddApplicationToCe < ActiveRecord::Migration | |
def self.up | |
add_column :continuing_educations, :origin_application, :string | |
say_with_time "Setting origin_application for all existing CEs" do | |
ContinuingEducation.find_each do |ce| | |
ce.update_attribute(:origin_application, "bank") | |
end | |
end | |
end | |
... | |
end |
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
== AddApplicationToCe: migrating ============================================= | |
-- add_column(:continuing_educations, :origin_application, :string) | |
-> 2.1238s | |
-- Setting origin_application for all existing CEs | |
-> 722.3896s | |
-> 254703 rows | |
== AddApplicationToCe: migrated (724.5134s) ==================================== |
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 AddApplicationToCe < ActiveRecord::Migration | |
def self.up | |
add_column :continuing_educations, :origin_application, :string | |
say_with_time "Setting origin_application for all existing CEs" do | |
ContinuingEducation.update_all "origin_application = 'bank'" | |
end | |
end | |
... | |
end |
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
== AddApplicationToCe: migrating ============================================= | |
-- add_column(:continuing_educations, :origin_application, :string) | |
-> 2.1238s | |
-- Setting origin_application for all existing CEs | |
-> 3.5165s | |
-> 254703 rows | |
== AddApplicationToCe: migrated (5.6485s) ==================================== |
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 AddApplicationToCe < ActiveRecord::Migration | |
def self.up | |
add_column :continuing_educations, :origin_application, :string | |
ContinuingEducation.reset_column_information | |
say_with_time "Setting origin_application for all existing CEs" do | |
ContinuingEducation.update_all "origin_application = 'bank'" | |
end | |
end | |
... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment