diff --git a/decidim-proposals/db/migrate/20240110203504_create_default_proposal_states.rb b/decidim-proposals/db/migrate/20240110203504_create_default_proposal_states.rb index 1f0a4dae514a1..5756c20746fec 100644 --- a/decidim-proposals/db/migrate/20240110203504_create_default_proposal_states.rb +++ b/decidim-proposals/db/migrate/20240110203504_create_default_proposal_states.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class CreateDefaultProposalStates < ActiveRecord::Migration[6.1] - class Proposal < ApplicationRecord + class CustomProposal < ApplicationRecord belongs_to :proposal_state, class_name: "Decidim::Proposals::ProposalState", foreign_key: "decidim_proposals_proposal_state_id", @@ -14,13 +14,16 @@ class Proposal < ApplicationRecord end def up + CustomProposal.reset_column_information + Decidim::Proposals::ProposalState.reset_column_information Decidim::Component.where(manifest_name: "proposals").find_each do |component| admin_user = component.organization.admins.first + Decidim::Proposals.create_default_states!(component, admin_user) - default_states = Decidim::Proposals.create_default_states!(component, admin_user) + CustomProposal.where(decidim_component_id: component.id).find_each do |proposal| + next if proposal.old_state == "not_answered" - Proposal.where(decidim_component_id: component.id).find_each do |proposal| - proposal.update!(proposal_state: default_states.dig(proposal.old_state.to_sym, :object)) + proposal.update!(proposal_state: Decidim::Proposals::ProposalState.where(component:, token: proposal.old_state).first!) end end end