Sha256: 8ddca7b6915e4fad0cb800640ef06ee0517a30e2d399afd89db24803ba36bcbb

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

class MigrateProposalReportsDataToReports < ActiveRecord::Migration[5.0]
  class Decidim::Proposals::ProposalReport < ApplicationRecord
    belongs_to :user, foreign_key: "decidim_user_id", class_name: "Decidim::User"
    belongs_to :proposal, foreign_key: "decidim_proposal_id", class_name: "Decidim::Proposals::Proposal"
  end

  def change
    Decidim::Proposals::ProposalReport.all.each do |proposal_report|
      moderation = Decidim::Moderation.find_or_create_by!(reportable: proposal_report.proposal,
                                                          participatory_process: proposal_report.proposal.feature.participatory_process)
      Decidim::Report.create!(moderation: moderation,
                              user: proposal_report.user,
                              reason: proposal_report.reason,
                              details: proposal_report.details)
      moderation.update_attributes!(report_count: moderation.report_count + 1)
    end

    drop_table :decidim_proposals_proposal_reports
    remove_column :decidim_proposals_proposals, :report_count
    remove_column :decidim_proposals_proposals, :hidden_at
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
decidim-proposals-0.3.2 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-0.3.2 decidim-proposals/db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.3.1 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-0.3.1 decidim-proposals/db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.3.0 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-0.3.0 decidim-proposals/db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb