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 26, 2020
1 parent 910f0d2 commit 48c0c6d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
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, :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
13 changes: 10 additions & 3 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: 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,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

Expand All @@ -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

Expand Down Expand Up @@ -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|
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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|
Expand All @@ -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|
Expand Down

0 comments on commit 48c0c6d

Please sign in to comment.