diff options
Diffstat (limited to 'spec/dummy/db/migrate/20110307025652_translate_custom_title_on_pages.rb')
m--------- | spec/dummy | 0 | ||||
-rw-r--r-- | spec/dummy/db/migrate/20110307025652_translate_custom_title_on_pages.rb | 41 |
2 files changed, 41 insertions, 0 deletions
diff --git a/spec/dummy b/spec/dummy deleted file mode 160000 -Subproject 36f851b7d5eca685475eb3a232e1d8dabfb1653 diff --git a/spec/dummy/db/migrate/20110307025652_translate_custom_title_on_pages.rb b/spec/dummy/db/migrate/20110307025652_translate_custom_title_on_pages.rb new file mode 100644 index 0000000..2bcecc7 --- /dev/null +++ b/spec/dummy/db/migrate/20110307025652_translate_custom_title_on_pages.rb @@ -0,0 +1,41 @@ +class TranslateCustomTitleOnPages < ActiveRecord::Migration + def self.up + unless ::Refinery::Page.translation_class.column_names.map(&:to_sym).include?(:custom_title) + add_column ::Refinery::Page.translation_class.table_name, :custom_title, :string + + say_with_time("Re-save custom_title") do + ::Refinery::Page.all.each do |page| + say "updating custom_title field for page##{page.id}" + page.update_attribute(:custom_title, page.untranslated_attributes['custom_title']) + end + end + else + say "Nothing done, ::Refinery::Page.translation_class table already includes a custom_title field" + end + + ::Refinery::Page.translation_class.reset_column_information + end + + def self.down + say_with_time("Re-save custom_title") do + ::Refinery::Page.all.each do |page| + if page.attributes['custom_title'].nil? + say "Nothing done, page##{page.id} custom_title field is nil" + else + say "updating custom_title field for page #{page.id}" + ::Refinery::Page.update_all({ + :custom_title => page.attributes['custom_title'] + }, { + :id => page.id.to_s + }) + end + end + end + + remove_column ::Refinery::Page.translation_class.table_name, :custom_title + + ::Refinery::Page.translated_attribute_names.delete(:custom_title) + + ::Refinery::Page.translation_class.reset_column_information + end +end |