-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc52734
commit af8af23
Showing
2 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
db/migrate/20240115111975_modify_default_proposal_states.decidim_custom_proposal_states.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
# This migration comes from decidim_custom_proposal_states (originally 20231102234909) | ||
|
||
class ModifyDefaultProposalStates < ActiveRecord::Migration[6.0] | ||
class Proposal < ApplicationRecord | ||
belongs_to :proposal_state, | ||
class_name: "Decidim::CustomProposalStates::ProposalState", | ||
foreign_key: "decidim_proposals_proposal_state_id", | ||
inverse_of: :proposals, | ||
optional: true | ||
|
||
self.table_name = :decidim_proposals_proposals | ||
end | ||
|
||
def up | ||
Decidim::Proposals::Proposal.where(state: "") | ||
.or(Decidim::Proposals::Proposal.where(state: nil)) | ||
.update_all(state: "not_answered") | ||
|
||
Decidim::Component.where(manifest_name: "proposals").find_each do |component| | ||
admin_user = component.organization.admins.first | ||
system_custom_proposal_states = Decidim::CustomProposalStates::ProposalState.where(component: component, system: true) | ||
next if system_custom_proposal_states.present? | ||
|
||
default_states = Decidim::CustomProposalStates.create_default_states!(component, admin_user).with_indifferent_access | ||
Proposal.where(decidim_component_id: component.id).find_each do |proposal| | ||
proposal.proposal_state = default_states.dig(proposal.state.to_s, :object) | ||
proposal.save! | ||
end | ||
end | ||
change_column_null :decidim_proposals_proposals, :decidim_proposals_proposal_state_id, false | ||
end | ||
|
||
def down; end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters