Sha256: b786a71b399be4a6f74efce17a69f4e459c6f15e1794c627d725cfa9bcc37503

Contents?: true

Size: 794 Bytes

Versions: 6

Compression:

Stored size: 794 Bytes

Contents

# frozen_string_literal: true

class MoveEnhancedTextworkAuthorshipsToCoauthorships < ActiveRecord::Migration[5.1]
  class Paragraph < ApplicationRecord
    self.table_name = :decidim_enhanced_textwork_paragraphs
  end
  class Coauthorship < ApplicationRecord
    self.table_name = :decidim_coauthorships
  end

  def change
    paragraphs = Paragraph.all

    paragraphs.each do |paragraph|
      author_id = paragraph.attributes["decidim_author_id"]
      user_group_id = paragraph.attributes["decidim_user_group_id"]

      next if author_id.nil?

      Coauthorship.create!(
        coauthorable_id: paragraph.id,
        coauthorable_type: "Decidim::EnhancedTextwork::Paragraph",
        decidim_author_id: author_id,
        decidim_user_group_id: user_group_id
      )
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-enhanced_textwork-1.0.5 db/migrate/20180529110230_move_enhanced_textwork_authorships_to_coauthorships.rb
decidim-enhanced_textwork-1.0.4 db/migrate/20180529110230_move_enhanced_textwork_authorships_to_coauthorships.rb
decidim-enhanced_textwork-1.0.3 db/migrate/20180529110230_move_enhanced_textwork_authorships_to_coauthorships.rb
decidim-enhanced_textwork-1.0.2 db/migrate/20180529110230_move_enhanced_textwork_authorships_to_coauthorships.rb
decidim-enhanced_textwork-1.0.1 db/migrate/20180529110230_move_enhanced_textwork_authorships_to_coauthorships.rb
decidim-enhanced_textwork-1.0.0 db/migrate/20180529110230_move_enhanced_textwork_authorships_to_coauthorships.rb