Sha256: c96455d469c6cfeaa89d80df57ff1996b7cd60dcf96f513cdf27ceb1b4232aa5

Contents?: true

Size: 1.14 KB

Versions: 77

Compression:

Stored size: 1.14 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.find_each do |proposal_report|
      moderation = Decidim::Moderation.find_or_create_by!(reportable: proposal_report.proposal,
                                                          participatory_process: proposal_report.proposal.feature.participatory_space)
      Decidim::Report.create!(moderation: moderation,
                              user: proposal_report.user,
                              reason: proposal_report.reason,
                              details: proposal_report.details)
      moderation.update!(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

77 entries across 77 versions & 1 rubygems

Version Path
decidim-proposals-0.27.9 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.27.8 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.27.7 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.27.6 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.26.10 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.26.9 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.27.5 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.26.8 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.27.4 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.27.3 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.26.7 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.26.5 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.27.2 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.27.1 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.26.4 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.27.0 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.26.3 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.27.0.rc2 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.27.0.rc1 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
decidim-proposals-0.26.2 db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb