Skip to content

Commit

Permalink
fix migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
microstudi committed Jan 19, 2024
1 parent 736cee7 commit b6bba4c
Show file tree
Hide file tree
Showing 18 changed files with 171 additions and 140 deletions.
14 changes: 0 additions & 14 deletions config/initializers/weird_conferences_fix.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ class AddIndexToDecidimProposalsProposalsProposalVotesCount < ActiveRecord::Migr
def change
add_index :decidim_proposals_proposals, :proposal_votes_count
add_index :decidim_proposals_proposals, :created_at
add_index :decidim_proposals_proposals, :state
# add_index :decidim_proposals_proposals, :state
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
# frozen_string_literal: true

class AddUniquenessToNameAndDocumentNumberToUserGroups < ActiveRecord::Migration[5.0]
class UserGroup < ApplicationRecord
self.table_name = :decidim_user_groups
end
def change
Decidim::UserGroup.select(:document_number).group(:document_number).having("count(*) > 1").count.keys.each do |document_number|
Decidim::UserGroup.where(document_number: document_number).each_with_index do |user_group, index|
UserGroup.select(:document_number).group(:document_number).having("count(*) > 1").count.keys.each do |document_number|
UserGroup.where(document_number: document_number).each_with_index do |user_group, index|
next if index.zero?

user_group.update_attribute(:document_number, "#{document_number} (#{index})")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ def change
add_column :decidim_module_sortitions_sortitions, :cancel_reason, :jsonb
add_column :decidim_module_sortitions_sortitions, :cancelled_on, :datetime
add_column :decidim_module_sortitions_sortitions, :cancelled_by_user_id, :integer
add_index :decidim_module_sortitions_sortitions, :cancelled_by_user_id
add_index :decidim_module_sortitions_sortitions, :cancelled_by_user_id, name: "index_sortitions_sortitions_on_cancelled_by_user_id"
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
# This migration comes from decidim (originally 20180810092428)

class MoveOrganizationFieldsToHeroContentBlock < ActiveRecord::Migration[5.2]
class ::Decidim::Organization < Decidim::ApplicationRecord
mount_uploader :homepage_image, ::Decidim::HomepageImageUploader
end
# class ::Decidim::Organization < Decidim::ApplicationRecord
# mount_uploader :homepage_image, ::Decidim::HomepageImageUploader
# end

def change
Decidim::ContentBlock.reset_column_information
Decidim::Organization.find_each do |organization|
content_block = Decidim::ContentBlock.find_by(organization: organization, scope: :homepage, manifest_name: :hero)
settings = {}
welcome_text = organization.welcome_text || {}
settings = welcome_text.inject(settings) { |acc, (k, v)| acc.update("welcome_text_#{k}" => v) }
# Decidim::ContentBlock.reset_column_information
# Decidim::Organization.find_each do |organization|
# content_block = Decidim::ContentBlock.find_by(organization: organization, scope: :homepage, manifest_name: :hero)
# settings = {}
# welcome_text = organization.welcome_text || {}
# settings = welcome_text.inject(settings) { |acc, (k, v)| acc.update("welcome_text_#{k}" => v) }

content_block.settings = settings
content_block.images_container.background_image = organization.homepage_image.file
content_block.settings_will_change!
content_block.images_will_change!
content_block.save!
end
# content_block.settings = settings
# content_block.images_container.background_image = organization.homepage_image.file
# content_block.settings_will_change!
# content_block.images_will_change!
# content_block.save!
# end

remove_column :decidim_organizations, :welcome_text
remove_column :decidim_organizations, :homepage_image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
class CreateDecidimFormsAnswers < ActiveRecord::Migration[5.0]
def change
create_table :decidim_forms_answers do |t|
t.jsonb :body, default: []
t.references :decidim_user, index: true
t.references :decidim_questionnaire, index: true
t.references :decidim_question, index: { name: "index_decidim_forms_answers_question_id" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
class AddDecidimUserGroupIdToDecidimConsultationsEndorsements < ActiveRecord::Migration[5.1]
def change
add_column :decidim_consultations_endorsements, :decidim_user_group_id, :integer
add_index :decidim_consultations_endorsements, :decidim_user_group_id
add_index :decidim_consultations_endorsements, :decidim_user_group_id, name: "index_consultations_endorsements_on_decidim_user_group_id"
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ def change
:integer
add_index :decidim_conferences_conference_registrations, :decidim_conference_registration_type_id, name: "idx_conference_registration_to_registration_type_id"
add_column :decidim_conferences_conference_registrations, :confirmed_at, :datetime
add_index :decidim_conferences_conference_registrations, :confirmed_at
add_index :decidim_conferences_conference_registrations, :confirmed_at, name: "idx_conference_registration_to_confirmed_at"
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class IndexForeignKeysInDecidimActionLogs < ActiveRecord::Migration[5.2]
def change
add_index :decidim_action_logs, :decidim_area_id
add_index :decidim_action_logs, :decidim_scope_id
add_index :decidim_action_logs, :version_id
# add_index :decidim_action_logs, :version_id
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This migration comes from decidim_comments (originally 20200320105911)

class IndexForeignKeysInDecidimCommentsComments < ActiveRecord::Migration[5.2]
def change
add_index :decidim_comments_comments, :decidim_user_group_id
end
# def change
# add_index :decidim_comments_comments, :decidim_user_group_id
# end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class IndexForeignKeysInDecidimInitiatives < ActiveRecord::Migration[5.2]
def change
add_index :decidim_initiatives, :decidim_user_group_id
add_index :decidim_initiatives, :scoped_type_id
# add_index :decidim_initiatives, :decidim_user_group_id
# add_index :decidim_initiatives, :scoped_type_id
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class IndexForeignKeysInDecidimInitiativesVotes < ActiveRecord::Migration[5.2]
def change
add_index :decidim_initiatives_votes, :decidim_user_group_id
# add_index :decidim_initiatives_votes, :decidim_user_group_id
add_index :decidim_initiatives_votes, :hash_id
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

class AddIndexToDecidimUsersNotificationsSendingFrequency < ActiveRecord::Migration[6.0]
def change
add_index :decidim_users, :notifications_sending_frequency
# add_index :decidim_users, :notifications_sending_frequency
end
end
Loading

0 comments on commit b6bba4c

Please sign in to comment.