Advertisement
twinfacer

asas

Apr 9th, 2014
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.06 KB | None | 0 0
  1. class ChangePageToSectionPageInSiteTemplates < ActiveRecord::Migration
  2.  
  3.   def up
  4.     remove_index :site_templates, :site_section_id
  5.     remove_index :site_templates, :page_id
  6.     remove_column :site_templates, :page_id
  7.     remove_column :site_templates, :site_section_id
  8.  
  9.     add_column :site_templates, :site_section_id, :integer, default: 0, null: false
  10.  
  11.     SiteTemplate.reset_column_information
  12.     SiteTemplate.all.each do |template|
  13.       template.site_section = template.site.site_sections.includes(:section).where("'sections'.'code' = 'core'").first
  14.       template.save!
  15.     end
  16.  
  17.     change_column :site_templates, :site_section_id, :integer, null: false
  18.  
  19.     add_column :site_templates, :section_page_id, :integer
  20.     add_index :site_templates, :site_section_id
  21.     add_index :site_templates, :section_page_id
  22.   end
  23.  
  24.   def down
  25.     remove_column :site_templates, :site_section_id
  26.     remove_column :site_templates, :section_page_id
  27.     remove_index :site_templates, :site_section_id
  28.     remove_index :site_templates, :section_page_id
  29.   end
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement