Sha256: 0f343c15720bc3e230e756a45f2dbf0b521d0ea384653a071a4ceda00acafb37
Contents?: true
Size: 1.45 KB
Versions: 6
Compression:
Stored size: 1.45 KB
Contents
# frozen_string_literal: true class ChangeDocumentPartsToPolymorphic < Lcms::Engine::Migration def up add_reference :document_parts, :renderer, polymorphic: true, index: true Lcms::Engine::DocumentPart.update_all("renderer_id = document_id, renderer_type = 'Lcms::Engine::Document'") Lcms::Engine::MaterialPart.find_each do |material_part| Lcms::Engine::DocumentPart.create!( active: material_part.active, content: material_part.content, context_type: material_part.context_type, part_type: material_part.part_type, renderer_id: material_part.material_id, renderer_type: 'Lcms::Engine::Material' ) end remove_column :document_parts, :document_id end def down Lcms::Engine::MaterialPart.delete_all Lcms::Engine::DocumentPart.where(renderer_type: 'Lcms::Engine::Material').find_each do |material_part| Lcms::Engine::MaterialPart.create!( active: material_part.active, content: material_part.content, context_type: material_part.context_type, part_type: material_part.part_type, material_id: material_part.renderer_id ) end Lcms::Engine::DocumentPart.where(renderer_type: 'Lcms::Engine::Material').delete_all add_reference :document_parts, :document, index: true, foreign_key: true Lcms::Engine::DocumentPart.update_all('document_id = renderer_id') remove_reference :document_parts, :renderer, polymorphic: true end end
Version data entries
6 entries across 6 versions & 1 rubygems