Skip to content

Commit

Permalink
Fix ProposalStates migration (decidim#13211)
Browse files Browse the repository at this point in the history
* Fix ProposalStates migration

* Lint

* Update decidim-proposals/db/migrate/20240110203504_create_default_proposal_states.rb
  • Loading branch information
alecslupu committed Oct 11, 2024
1 parent 462ea87 commit 03c9b18
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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
Expand Down

0 comments on commit 03c9b18

Please sign in to comment.