Sha256: 6f02d6a22c9e6d735de32bc3fac551bc33f294ec09dba6b02f61d045de9ee8fd

Contents?: true

Size: 1009 Bytes

Versions: 6

Compression:

Stored size: 1009 Bytes

Contents

# frozen_string_literal: true

class FixProposalsDataToEnsureTitleAndBodyAreHashes < ActiveRecord::Migration[5.2]
  def up
    reset_column_information

    PaperTrail.request(enabled: false) do
      Decidim::Proposals::Proposal.find_each do |proposal|
        next if proposal.title.is_a?(Hash) && proposal.body.is_a?(Hash)

        author = proposal.coauthorships.first.author

        locale = author.try(:locale).presence || author.try(:default_locale).presence || author.try(:organization).try(:default_locale).presence

        proposal.title = {
          locale => proposal.title
        }
        proposal.body = {
          locale => proposal.body
        }

        proposal.save!
      end
    end

    reset_column_information
  end

  def down; end

  def reset_column_information
    Decidim::User.reset_column_information
    Decidim::Coauthorship.reset_column_information
    Decidim::Proposals::Proposal.reset_column_information
    Decidim::Organization.reset_column_information
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-proposals-0.24.0.rc1 db/migrate/20200915151348_fix_proposals_data_to_ensure_title_and_body_are_hashes.rb
decidim-proposals-0.23.3 db/migrate/20200915151348_fix_proposals_data_to_ensure_title_and_body_are_hashes.rb
decidim-proposals-0.23.2 db/migrate/20200915151348_fix_proposals_data_to_ensure_title_and_body_are_hashes.rb
decidim-proposals-0.23.1 db/migrate/20200915151348_fix_proposals_data_to_ensure_title_and_body_are_hashes.rb
decidim-proposals-0.23.1.rc1 db/migrate/20200915151348_fix_proposals_data_to_ensure_title_and_body_are_hashes.rb
decidim-proposals-0.23.0 db/migrate/20200915151348_fix_proposals_data_to_ensure_title_and_body_are_hashes.rb