Sha256: edf380f42df130faf1aca2bbb97965142c50aa010f8109953d2b4c1385e7d990
Contents?: true
Size: 899 Bytes
Versions: 2
Compression:
Stored size: 899 Bytes
Contents
class LocalizePublishColumn < ActiveRecord::Migration def up rename_column :qbrick_pages, :published, :published_en add_column :qbrick_pages, :published_de, :integer, default: 0 I18n.available_locales.each do |locale| column_name = :"published_#{locale.to_s.underscore}" add_column :qbrick_pages, column_name, :integer, default: 0 unless column_exists? :qbrick_pages, column_name end new_translations = Qbrick::Page.translated_columns_for(:published) - %w(published_en) Qbrick::Page.all.each do |page| page.update Hash[new_translations.zip([page.published_en] * new_translations.count)] end end def down translated_columns = Qbrick::Page.translated_columns_for(:published) - %w(published_en) rename_column :qbrick_pages, :published_en translated_columns.each do |column| remove_column :qbrick_pages, column end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
qbrick-2.6.1 | db/migrate/24_localize_publish_column.rb |
qbrick-2.6.0 | db/migrate/24_localize_publish_column.rb |