Skip to content

Commit

Permalink
fix: Modify default proposal states
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentinchampenois authored and moustachu committed May 6, 2024
1 parent fc52734 commit af8af23
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
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
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_01_15_111974) do
ActiveRecord::Schema.define(version: 2024_01_15_111975) do

# These are extensions that must be enabled in order to support this database
enable_extension "ltree"
Expand Down Expand Up @@ -1360,7 +1360,7 @@
t.jsonb "body"
t.integer "comments_count", default: 0, null: false
t.integer "follows_count", default: 0, null: false
t.integer "decidim_proposals_proposal_state_id"
t.integer "decidim_proposals_proposal_state_id", null: false
t.index "md5((body)::text)", name: "decidim_proposals_proposal_body_search"
t.index "md5((title)::text)", name: "decidim_proposals_proposal_title_search"
t.index ["answered_at"], name: "index_decidim_proposals_proposals_on_answered_at"
Expand Down

0 comments on commit af8af23

Please sign in to comment.