Sha256: 2b1ac82366ac4c58295b934e8154aa73db0deba91b32ee14e3fbf3b4b1d76d0e

Contents?: true

Size: 1.26 KB

Versions: 25

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

class VotesEnabledToVotesChoices < ActiveRecord::Migration[5.2]
  class Component < ApplicationRecord
    self.table_name = :decidim_components
  end

  def up
    budget_components.each do |component|
      steps = component["settings"] && component["settings"]["steps"]
      default_step = component["settings"] && component["settings"]["default_step"]

      if steps.present?
        new_steps_settings = component["settings"]["steps"].each_with_object({}) do |(step, config), new_config|
          votes_value = config["votes_enabled"] ? "enabled" : "disabled"

          new_config[step] = config.merge(votes: votes_value).except("votes_enabled")
          new_config
        end
        component["settings"]["steps"] = new_steps_settings
        component.save!
      elsif default_step.present?
        votes_value = component["settings"]["default_step"]["votes_enabled"] ? "enabled" : "disabled"

        new_default_step_settings = component["settings"]["default_step"].merge(votes: votes_value).except("votes_enabled")
        component["settings"]["default_step"] = new_default_step_settings
        component.save!
      end
    end
  end

  def budget_components
    @budget_components ||= Component.where(manifest_name: "budgets")
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-budgets-0.29.1 db/migrate/20200804175222_votes_enabled_to_votes_choices.rb
decidim-budgets-0.28.4 db/migrate/20200804175222_votes_enabled_to_votes_choices.rb
decidim-budgets-0.27.9 db/migrate/20200804175222_votes_enabled_to_votes_choices.rb
decidim-budgets-0.29.0 db/migrate/20200804175222_votes_enabled_to_votes_choices.rb
decidim-budgets-0.28.3 db/migrate/20200804175222_votes_enabled_to_votes_choices.rb
decidim-budgets-0.27.8 db/migrate/20200804175222_votes_enabled_to_votes_choices.rb
decidim-budgets-0.29.0.rc4 db/migrate/20200804175222_votes_enabled_to_votes_choices.rb
decidim-budgets-0.29.0.rc3 db/migrate/20200804175222_votes_enabled_to_votes_choices.rb
decidim-budgets-0.29.0.rc2 db/migrate/20200804175222_votes_enabled_to_votes_choices.rb
decidim-budgets-0.29.0.rc1 db/migrate/20200804175222_votes_enabled_to_votes_choices.rb
decidim-budgets-0.28.2 db/migrate/20200804175222_votes_enabled_to_votes_choices.rb
decidim-budgets-0.27.7 db/migrate/20200804175222_votes_enabled_to_votes_choices.rb
decidim-budgets-0.28.1 db/migrate/20200804175222_votes_enabled_to_votes_choices.rb
decidim-budgets-0.27.6 db/migrate/20200804175222_votes_enabled_to_votes_choices.rb
decidim-budgets-0.28.0 db/migrate/20200804175222_votes_enabled_to_votes_choices.rb
decidim-budgets-0.27.5 db/migrate/20200804175222_votes_enabled_to_votes_choices.rb
decidim-budgets-0.28.0.rc5 db/migrate/20200804175222_votes_enabled_to_votes_choices.rb
decidim-budgets-0.28.0.rc4 db/migrate/20200804175222_votes_enabled_to_votes_choices.rb
decidim-budgets-0.27.4 db/migrate/20200804175222_votes_enabled_to_votes_choices.rb
decidim-budgets-0.27.3 db/migrate/20200804175222_votes_enabled_to_votes_choices.rb