Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ChangePageToSectionPageInSiteTemplates < ActiveRecord::Migration
- def up
- remove_index :site_templates, :page_id
- remove_column :site_templates, :page_id
- SiteTemplate.reset_column_information
- site_section = nil
- Site.all.each do |site|
- site_section = site.site_sections.includes(:section).where("'sections'.'code' = 'core'").first
- if site_section.nil?
- core = Section.find_by_code("core")
- site.site_sections.create(section: core, status: "active")
- site_section = site.site_sections.includes(:section).where("'sections'.'code' = 'core'").first
- end
- end
- SiteTemplate.all.each do |template|
- template.site_section = site_section
- template.save!
- end
- change_column :site_templates, :site_section_id, :integer, null: false
- add_column :site_templates, :section_page_id, :integer
- add_index :site_templates, :section_page_id
- end
- def down
- remove_index :site_templates, :section_page_id
- remove_column :site_templates, :section_page_id
- change_column :site_templates, :site_section_id, :integer
- add_column :site_templates, :page_id, :integer
- add_index :site_templates, :page_id
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement