From 48c0c6d538eeca42081e223b1c7cc64a5a111bc3 Mon Sep 17 00:00:00 2001 From: Jon Hallam Date: Thu, 26 Mar 2020 11:25:29 +0000 Subject: [PATCH] Fix linting issues by creating new indexes https://github.com/rubocop-hq/rubocop-rails/pull/197 introduced a new cop to rubocop-rails that checks for unique validation on an index if it's present in the model. This caused a number of failures when upgrading to 2.5.0 that this fixes. --- db/migrate/20200326094046_index_creation.rb | 30 +++++++++++++++++++++ db/schema.rb | 13 ++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20200326094046_index_creation.rb diff --git a/db/migrate/20200326094046_index_creation.rb b/db/migrate/20200326094046_index_creation.rb new file mode 100644 index 000000000000..c7c1fa2ee2d5 --- /dev/null +++ b/db/migrate/20200326094046_index_creation.rb @@ -0,0 +1,30 @@ +class IndexCreation < ActiveRecord::Migration[5.1] + def change + remove_index :about_pages, :name if index_exists?(:about_pages, :name) + add_index :about_pages, :name, unique: true + + remove_index :classifications, :name if index_exists?(:classifications, :name) + add_index :classifications, :name, unique: true + + remove_index :classification_relations, :classification_id if index_exists?(:classification_relations, :classification_id) + add_index :classification_relations, :classification_id, uniqueness: { scope: :related_classification_id } + + remove_index :document_collection_groups, :heading if index_exists?(:document_collection_groups, :heading) + add_index :document_collection_groups, :heading, uniqueness: { scope: :document_collection_id } + + remove_index :edition_relations, :document_id if index_exists?(:edition_relations, :document_id) + add_index :edition_relations, :document_id, uniqueness: { scope: :edition_id } + + remove_index :operational_fields, :name if index_exists?(:operational_fields, :name) + add_index :operational_fields, :name, unique: true + + remove_index :related_mainstreams, :content_id if index_exists?(:related_mainstreams, :content_id) + add_index :related_mainstreams, :content_id, uniqueness: { scope: :edition_id } + + remove_index :social_media_services, :name if index_exists?(:social_media_services, :name) + add_index :social_media_services, :name, unique: true + + remove_index :specialist_sectors, :topic_content_id if index_exists?(:specialist_sectors, :topic_content_id) + add_index :specialist_sectors, :topic_content_id, uniqueness: { scope: :edition_id } + end +end diff --git a/db/schema.rb b/db/schema.rb index dc5adbc49d72..e82c87b569e3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20200211132528) do +ActiveRecord::Schema.define(version: 20200326094046) do create_table "about_pages", id: :integer, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci" do |t| t.integer "topical_event_id" @@ -21,6 +21,7 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "content_id" + t.index ["name"], name: "index_about_pages_on_name", unique: true end create_table "access_and_opening_times", id: :integer, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci" do |t| @@ -134,7 +135,7 @@ t.integer "related_classification_id", null: false t.datetime "created_at" t.datetime "updated_at" - t.index ["classification_id"], name: "index_classification_relations_on_classification_id" + t.index ["classification_id"], name: "index_classification_relations_on_classification_id", unique: true t.index ["related_classification_id"], name: "index_classification_relations_on_related_classification_id" end @@ -151,6 +152,7 @@ t.date "start_date" t.date "end_date" t.string "content_id" + t.index ["name"], name: "index_classifications_on_name", unique: true t.index ["slug"], name: "index_classifications_on_slug" end @@ -260,6 +262,7 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["document_collection_id", "ordering"], name: "index_dc_groups_on_dc_id_and_ordering" + t.index ["heading"], name: "index_document_collection_groups_on_heading", unique: true end create_table "document_collection_non_whitehall_links", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| @@ -333,7 +336,7 @@ t.datetime "created_at" t.datetime "updated_at" t.integer "document_id" - t.index ["document_id"], name: "index_edition_relations_on_document_id" + t.index ["document_id"], name: "index_edition_relations_on_document_id", unique: true t.index ["edition_id"], name: "index_edition_relations_on_edition_id" end @@ -697,6 +700,7 @@ t.text "description" t.string "slug" t.string "content_id" + t.index ["name"], name: "index_operational_fields_on_name", unique: true t.index ["slug"], name: "index_operational_fields_on_slug" end @@ -866,6 +870,7 @@ t.boolean "additional", default: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["content_id"], name: "index_related_mainstreams_on_content_id", unique: true t.index ["edition_id"], name: "index_related_mainstreams_on_edition_id" end @@ -950,6 +955,7 @@ t.string "name" t.datetime "created_at" t.datetime "updated_at" + t.index ["name"], name: "index_social_media_services_on_name", unique: true end create_table "specialist_sectors", id: :integer, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci" do |t| @@ -960,6 +966,7 @@ t.boolean "primary", default: false t.string "topic_content_id" t.index ["edition_id", "tag"], name: "index_specialist_sectors_on_edition_id_and_tag", unique: true + t.index ["topic_content_id"], name: "index_specialist_sectors_on_topic_content_id", unique: true end create_table "sponsorships", id: :integer, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|