Skip to content

Commit

Permalink
Fix linting issues by creating new indexes
Browse files Browse the repository at this point in the history
rubocop/rubocop-rails#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.
  • Loading branch information
JonathanHallam committed Mar 30, 2020
1 parent 910f0d2 commit 27755e2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
30 changes: 30 additions & 0 deletions db/migrate/20200326094046_index_creation.rb
Original file line number Diff line number Diff line change
@@ -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, %i(classification_id related_classification_id) if index_exists?(:classification_relations, %i(classification_id related_classification_id))
add_index :classification_relations, %i(classification_id related_classification_id), unique: true, name: "index_classification_relations_on_id_and_related_id"

remove_index :document_collection_groups, %i(heading document_collection_id) if index_exists?(:document_collection_groups, %i(heading document_collection_id))
add_index :document_collection_groups, %i(heading document_collection_id), unique: true, name: "index_doc_collection_groups_on_heading_and_doc_collection_id"

remove_index :edition_relations, %i(document_id edition_id) if index_exists?(:edition_relations, %i(document_id edition_id))
add_index :edition_relations, %i(document_id edition_id), unique: true

remove_index :operational_fields, :name if index_exists?(:operational_fields, :name)
add_index :operational_fields, :name, unique: true

remove_index :related_mainstreams, %i(content_id edition_id) if index_exists?(:related_mainstreams, %i(content_id edition_id))
add_index :related_mainstreams, %i(content_id edition_id), unique: true

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, %i(topic_content_id edition_id) if index_exists?(:specialist_sectors, %i(topic_content_id edition_id))
add_index :specialist_sectors, %i(topic_content_id edition_id), unique: true
end
end
11 changes: 10 additions & 1 deletion 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: 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"
Expand All @@ -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|
Expand Down Expand Up @@ -134,6 +135,7 @@
t.integer "related_classification_id", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.index ["classification_id", "related_classification_id"], name: "index_classification_relations_on_id_and_related_id", unique: true
t.index ["classification_id"], name: "index_classification_relations_on_classification_id"
t.index ["related_classification_id"], name: "index_classification_relations_on_related_classification_id"
end
Expand All @@ -151,6 +153,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

Expand Down Expand Up @@ -260,6 +263,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", "document_collection_id"], name: "index_doc_collection_groups_on_heading_and_doc_collection_id", unique: true
end

create_table "document_collection_non_whitehall_links", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
Expand Down Expand Up @@ -333,6 +337,7 @@
t.datetime "created_at"
t.datetime "updated_at"
t.integer "document_id"
t.index ["document_id", "edition_id"], name: "index_edition_relations_on_document_id_and_edition_id", unique: true
t.index ["document_id"], name: "index_edition_relations_on_document_id"
t.index ["edition_id"], name: "index_edition_relations_on_edition_id"
end
Expand Down Expand Up @@ -697,6 +702,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

Expand Down Expand Up @@ -866,6 +872,7 @@
t.boolean "additional", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["content_id", "edition_id"], name: "index_related_mainstreams_on_content_id_and_edition_id", unique: true
t.index ["edition_id"], name: "index_related_mainstreams_on_edition_id"
end

Expand Down Expand Up @@ -950,6 +957,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|
Expand All @@ -960,6 +968,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", "edition_id"], name: "index_specialist_sectors_on_topic_content_id_and_edition_id", unique: true
end

create_table "sponsorships", id: :integer, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
Expand Down

0 comments on commit 27755e2

Please sign in to comment.