Skip to content

Commit

Permalink
Ensure that the migration doesn't fail if the field already exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
parndt committed Mar 8, 2011
1 parent 46f5ef2 commit 0d323bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
15 changes: 10 additions & 5 deletions db/migrate/20110307025652_translate_custom_title_on_pages.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
class TranslateCustomTitleOnPages < ActiveRecord::Migration
def self.up
add_column ::Page::Translation.table_name, :custom_title, :string
unless ::Page::Translation.column_names.map(&:to_sym).include?(:custom_title)
add_column ::Page::Translation.table_name, :custom_title, :string

# Re-save custom_title
::Page.all.each do |page|
page.update_attribute(:custom_title, page.untranslated_attributes['custom_title'])
end

# Re-save custom_title
::Page.all.each do |page|
page.update_attribute(:custom_title, page.untranslated_attributes['custom_title'])
end

remove_column ::Page.table_name, :custom_title
if ::Page.column_names.map(&:to_sym).include?(:custom_title)
remove_column ::Page.table_name, :custom_title
end
end

def self.down
Expand Down
15 changes: 10 additions & 5 deletions pages/db/migrate/20110307025652_translate_custom_title_on_pages.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
class TranslateCustomTitleOnPages < ActiveRecord::Migration
def self.up
add_column ::Page::Translation.table_name, :custom_title, :string
unless ::Page::Translation.column_names.map(&:to_sym).include?(:custom_title)
add_column ::Page::Translation.table_name, :custom_title, :string

# Re-save custom_title
::Page.all.each do |page|
page.update_attribute(:custom_title, page.untranslated_attributes['custom_title'])
end

# Re-save custom_title
::Page.all.each do |page|
page.update_attribute(:custom_title, page.untranslated_attributes['custom_title'])
end

remove_column ::Page.table_name, :custom_title
if ::Page.column_names.map(&:to_sym).include?(:custom_title)
remove_column ::Page.table_name, :custom_title
end
end

def self.down
Expand Down

0 comments on commit 0d323bb

Please sign in to comment.