Sha256: 874697f11c82e3f511882e15f378eccc4ca49cb126d9a58096432d2dfa954307

Contents?: true

Size: 980 Bytes

Versions: 14

Compression:

Stored size: 980 Bytes

Contents

# frozen_string_literal: true

class FixProposalsData < 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

14 entries across 14 versions & 1 rubygems

Version Path
decidim-proposals-0.24.3 db/migrate/20201002085508_fix_proposals_data.rb
decidim-proposals-0.23.6 db/migrate/20201002085508_fix_proposals_data.rb
decidim-proposals-0.24.2 db/migrate/20201002085508_fix_proposals_data.rb
decidim-proposals-0.23.5 db/migrate/20201002085508_fix_proposals_data.rb
decidim-proposals-0.24.1 db/migrate/20201002085508_fix_proposals_data.rb
decidim-proposals-0.24.0 db/migrate/20201002085508_fix_proposals_data.rb
decidim-proposals-0.24.0.rc2 db/migrate/20201002085508_fix_proposals_data.rb
decidim-proposals-0.23.4 db/migrate/20201002085508_fix_proposals_data.rb
decidim-proposals-0.24.0.rc1 db/migrate/20201002085508_fix_proposals_data.rb
decidim-proposals-0.23.3 db/migrate/20201002085508_fix_proposals_data.rb
decidim-proposals-0.23.2 db/migrate/20201002085508_fix_proposals_data.rb
decidim-proposals-0.23.1 db/migrate/20201002085508_fix_proposals_data.rb
decidim-proposals-0.23.1.rc1 db/migrate/20201002085508_fix_proposals_data.rb
decidim-proposals-0.23.0 db/migrate/20201002085508_fix_proposals_data.rb