Sha256: 90530eea87ad3d98b2eb0346584ed4bb89c0c173e2b5ecf609c8b706f3bfff41

Contents?: true

Size: 1.29 KB

Versions: 75

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

class RenameVoteIndexesToEndorsementIndexes < ActiveRecord::Migration[5.1]
  def change
    rename_index :decidim_consultations_endorsements,
                 :index_consultations_votes_on_author,
                 :index_consultations_endorsements_on_author

    rename_index :decidim_consultations_endorsements,
                 :index_consultations_votes_on_consultation_question,
                 :index_consultations_endorsements_on_consultation_question

    reversible do |dir|
      dir.up { create_authorable_unique }
      dir.down { create_author_unique }
    end
  end

  def create_authorable_unique
    remove_index :decidim_consultations_endorsements, name: "index_question_votes_author_unique"

    add_index :decidim_consultations_endorsements,
              %w(decidim_consultation_question_id decidim_author_id decidim_user_group_id),
              name: "index_question_votes_author_unique",
              unique: true
  end

  def create_author_unique
    remove_index :decidim_consultations_endorsements, name: "index_question_votes_author_unique"

    add_index :decidim_consultations_endorsements,
              %w(decidim_consultation_question_id decidim_author_id),
              name: "index_question_votes_author_unique",
              unique: true
  end
end

Version data entries

75 entries across 75 versions & 1 rubygems

Version Path
decidim-consultations-0.15.0 db/migrate/20180130142411_rename_vote_indexes_to_endorsement_indexes.rb
decidim-consultations-0.14.4 db/migrate/20180130142411_rename_vote_indexes_to_endorsement_indexes.rb
decidim-consultations-0.14.3 db/migrate/20180130142411_rename_vote_indexes_to_endorsement_indexes.rb
decidim-consultations-0.14.2 db/migrate/20180130142411_rename_vote_indexes_to_endorsement_indexes.rb
decidim-consultations-0.14.1 db/migrate/20180130142411_rename_vote_indexes_to_endorsement_indexes.rb
decidim-consultations-0.13.1 db/migrate/20180130142411_rename_vote_indexes_to_endorsement_indexes.rb
decidim-consultations-0.12.2 db/migrate/20180130142411_rename_vote_indexes_to_endorsement_indexes.rb
decidim-consultations-0.13.0 db/migrate/20180130142411_rename_vote_indexes_to_endorsement_indexes.rb
decidim-consultations-0.12.1 db/migrate/20180130142411_rename_vote_indexes_to_endorsement_indexes.rb
decidim-consultations-0.13.0.pre1 db/migrate/20180130142411_rename_vote_indexes_to_endorsement_indexes.rb
decidim-consultations-0.12.0 db/migrate/20180130142411_rename_vote_indexes_to_endorsement_indexes.rb
decidim-consultations-0.11.2 db/migrate/20180130142411_rename_vote_indexes_to_endorsement_indexes.rb
decidim-consultations-0.12.0.pre db/migrate/20180130142411_rename_vote_indexes_to_endorsement_indexes.rb
decidim-consultations-0.11.1 db/migrate/20180130142411_rename_vote_indexes_to_endorsement_indexes.rb
decidim-consultations-0.11.0.pre1 db/migrate/20180130142411_rename_vote_indexes_to_endorsement_indexes.rb