From 521edd5e8c7a9f4126e04ba904ebd75067ee9ee7 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Fri, 10 Jan 2025 08:16:35 -0500 Subject: [PATCH 1/7] Add new tooling for making sure db schema up to snuff --- Gemfile | 3 +-- Gemfile.lock | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index fb8fde5ab..a5ac8a8da 100644 --- a/Gemfile +++ b/Gemfile @@ -71,8 +71,7 @@ group :development do # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] # gem 'rack-mini-profiler' - # # Highlight the fine-grained location where an error occurred [https://github.com/ruby/error_highlight] - + gem "database_consistency", "~> 2.0", require: false gem 'debugbar' gem 'derailed_benchmarks' gem 'letter_opener' diff --git a/Gemfile.lock b/Gemfile.lock index 486519337..76d755a19 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -151,6 +151,8 @@ GEM csv (3.3.2) d3-rails (3.5.17) railties (>= 3.1) + database_consistency (2.0.3) + activerecord (>= 3.2) date (3.4.1) debug (1.10.0) irb (~> 1.10) @@ -563,6 +565,7 @@ DEPENDENCIES capybara colorize d3-rails (~> 3.5.5) + database_consistency (~> 2.0) debug debugbar derailed_benchmarks From 624b61e8b67c44b0e159e757127180a8c1902338 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Fri, 10 Jan 2025 08:40:24 -0500 Subject: [PATCH 2/7] lint --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index a5ac8a8da..c65d25871 100644 --- a/Gemfile +++ b/Gemfile @@ -71,7 +71,7 @@ group :development do # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] # gem 'rack-mini-profiler' - gem "database_consistency", "~> 2.0", require: false + gem 'database_consistency', '~> 2.0', require: false gem 'debugbar' gem 'derailed_benchmarks' gem 'letter_opener' From a90fd180961c3b8cf65137a24620cb7c2a56ca35 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Fri, 10 Jan 2025 08:40:40 -0500 Subject: [PATCH 3/7] First add --- .database_consistency.todo.yml | 526 +++++++++++++++++++++++++++++++++ .database_consistency.yml | 9 + 2 files changed, 535 insertions(+) create mode 100644 .database_consistency.todo.yml create mode 100644 .database_consistency.yml diff --git a/.database_consistency.todo.yml b/.database_consistency.todo.yml new file mode 100644 index 000000000..609cba2cb --- /dev/null +++ b/.database_consistency.todo.yml @@ -0,0 +1,526 @@ +--- +Ahoy::Event: + name: + LengthConstraintChecker: + enabled: false + user: + ForeignKeyChecker: + enabled: false + visit: + ColumnPresenceChecker: + enabled: false + ForeignKeyChecker: + enabled: false +Ahoy::Visit: + app_version: + LengthConstraintChecker: + enabled: false + browser: + LengthConstraintChecker: + enabled: false + city: + LengthConstraintChecker: + enabled: false + country: + LengthConstraintChecker: + enabled: false + device_type: + LengthConstraintChecker: + enabled: false + index_ahoy_visits_on_visit_token: + UniqueIndexChecker: + enabled: false + ip: + LengthConstraintChecker: + enabled: false + landing_page: + LengthConstraintChecker: + enabled: false + os: + LengthConstraintChecker: + enabled: false + os_version: + LengthConstraintChecker: + enabled: false + platform: + LengthConstraintChecker: + enabled: false + referrer: + LengthConstraintChecker: + enabled: false + referring_domain: + LengthConstraintChecker: + enabled: false + region: + LengthConstraintChecker: + enabled: false + user: + ForeignKeyChecker: + enabled: false + user_agent: + LengthConstraintChecker: + enabled: false + utm_campaign: + LengthConstraintChecker: + enabled: false + utm_content: + LengthConstraintChecker: + enabled: false + utm_medium: + LengthConstraintChecker: + enabled: false + utm_source: + LengthConstraintChecker: + enabled: false + utm_term: + LengthConstraintChecker: + enabled: false + visit_token: + LengthConstraintChecker: + enabled: false + visitor_token: + LengthConstraintChecker: + enabled: false +Annotation: + id: + PrimaryKeyTypeChecker: + enabled: false + message: + LengthConstraintChecker: + enabled: false + score: + MissingIndexChecker: + enabled: false + source: + LengthConstraintChecker: + enabled: false + user: + ColumnPresenceChecker: + enabled: false +Announcement: + announcement_viewed: + MissingIndexChecker: + enabled: true + author: + ColumnPresenceChecker: + enabled: false + ForeignKeyChecker: + enabled: false + live: + MissingUniqueIndexChecker: + enabled: false + ThreeStateBooleanChecker: + enabled: false + text: + ColumnPresenceChecker: + enabled: false +AnnouncementViewed: + announcement: + ColumnPresenceChecker: + enabled: false + ForeignKeyChecker: + enabled: false + user: + ColumnPresenceChecker: + enabled: false + ForeignKeyChecker: + enabled: false +ApiKey: + token_digest: + LengthConstraintChecker: + enabled: false + NullConstraintChecker: + enabled: false + user: + ColumnPresenceChecker: + enabled: false + ForeignKeyChecker: + enabled: false +Book: + cases: + MissingIndexChecker: + enabled: true + export_job: + LengthConstraintChecker: + enabled: false + import_job: + LengthConstraintChecker: + enabled: false + name: + LengthConstraintChecker: + enabled: false + owner: + ForeignKeyChecker: + enabled: false + populate_job: + LengthConstraintChecker: + enabled: false + scorer: + ColumnPresenceChecker: + enabled: false + ForeignKeyChecker: + enabled: false + show_rank: + ThreeStateBooleanChecker: + enabled: false + support_implicit_judgements: + ThreeStateBooleanChecker: + enabled: false +BookMetadatum: + user: + ColumnPresenceChecker: + enabled: false + ForeignKeyChecker: + enabled: false +Case: + archived: + ThreeStateBooleanChecker: + enabled: false + book: + ForeignKeyChecker: + enabled: false + case_name: + ColumnPresenceChecker: + enabled: false + LengthConstraintChecker: + enabled: false + id: + PrimaryKeyTypeChecker: + enabled: false + nightly: + ThreeStateBooleanChecker: + enabled: false + public: + ThreeStateBooleanChecker: + enabled: false + scorer: + ForeignKeyChecker: + enabled: false +CaseMetadatum: + id: + PrimaryKeyTypeChecker: + enabled: false +CuratorVariable: + id: + PrimaryKeyTypeChecker: + enabled: false + name: + ColumnPresenceChecker: + enabled: false + LengthConstraintChecker: + enabled: false + try: + ColumnPresenceChecker: + enabled: false + ForeignKeyChecker: + enabled: false + value: + ColumnPresenceChecker: + enabled: false +Judgement: + explanation: + LengthConstraintChecker: + enabled: false + judge_later: + ThreeStateBooleanChecker: + enabled: false + unrateable: + ThreeStateBooleanChecker: + enabled: false + user: + ForeignKeyChecker: + enabled: false +Permission: + action: + LengthConstraintChecker: + enabled: false + id: + PrimaryKeyTypeChecker: + enabled: false + model_type: + LengthConstraintChecker: + enabled: false + 'on': + ThreeStateBooleanChecker: + enabled: false + user: + ColumnPresenceChecker: + enabled: false + ForeignKeyChecker: + enabled: false +Query: + case: + ColumnPresenceChecker: + enabled: false + id: + PrimaryKeyTypeChecker: + enabled: false + information_need: + LengthConstraintChecker: + enabled: false + notes: + LengthConstraintChecker: + enabled: false + options: + LengthConstraintChecker: + enabled: false + query_text: + ColumnPresenceChecker: + enabled: false +QueryDocPair: + doc_id: + ColumnPresenceChecker: + enabled: false + LengthConstraintChecker: + enabled: false + document_fields: + LengthConstraintChecker: + enabled: false + information_need: + LengthConstraintChecker: + enabled: false + notes: + LengthConstraintChecker: + enabled: false + options: + LengthConstraintChecker: + enabled: false + query_text: + ColumnPresenceChecker: + enabled: false +Rating: + doc_id: + LengthConstraintChecker: + enabled: false + id: + PrimaryKeyTypeChecker: + enabled: false + query: + ColumnPresenceChecker: + enabled: false + user: + ForeignKeyChecker: + enabled: false +Score: + all_rated: + ThreeStateBooleanChecker: + enabled: false + case: + ColumnPresenceChecker: + enabled: false + id: + PrimaryKeyTypeChecker: + enabled: false + try: + ColumnPresenceChecker: + enabled: false + ForeignKeyChecker: + enabled: false + user: + ColumnPresenceChecker: + enabled: false +Scorer: + code: + LengthConstraintChecker: + enabled: false + communal: + ThreeStateBooleanChecker: + enabled: false + id: + PrimaryKeyTypeChecker: + enabled: false + name: + LengthConstraintChecker: + enabled: false + owner: + ForeignKeyChecker: + enabled: false + scale: + LengthConstraintChecker: + enabled: false + scale_with_labels: + LengthConstraintChecker: + enabled: false + show_scale_labels: + ThreeStateBooleanChecker: + enabled: false +SearchEndpoint: + api_method: + LengthConstraintChecker: + enabled: false + archived: + ThreeStateBooleanChecker: + enabled: false + basic_auth_credential: + LengthConstraintChecker: + enabled: false + custom_headers: + LengthConstraintChecker: + enabled: false + endpoint_url: + LengthConstraintChecker: + enabled: false + mapper_code: + LengthConstraintChecker: + enabled: false + name: + LengthConstraintChecker: + enabled: false + owner: + ForeignKeyChecker: + enabled: false + proxy_requests: + ThreeStateBooleanChecker: + enabled: false + search_engine: + LengthConstraintChecker: + enabled: false +SelectionStrategy: + description: + LengthConstraintChecker: + enabled: false + name: + LengthConstraintChecker: + enabled: false +Snapshot: + id: + PrimaryKeyTypeChecker: + enabled: false + name: + ColumnPresenceChecker: + enabled: false + LengthConstraintChecker: + enabled: false + scorer: + ForeignKeyChecker: + enabled: false + try: + ForeignKeyChecker: + enabled: false +SnapshotDoc: + doc_id: + LengthConstraintChecker: + enabled: false + explain: + LengthConstraintChecker: + enabled: false + fields: + LengthConstraintChecker: + enabled: false + id: + PrimaryKeyTypeChecker: + enabled: false + rated_only: + ThreeStateBooleanChecker: + enabled: false +SnapshotQuery: + all_rated: + ThreeStateBooleanChecker: + enabled: false + id: + PrimaryKeyTypeChecker: + enabled: false + snapshot_docs: + ForeignKeyCascadeChecker: + enabled: false +Team: + id: + PrimaryKeyTypeChecker: + enabled: false + name: + ColumnPresenceChecker: + enabled: false + LengthConstraintChecker: + enabled: false + MissingUniqueIndexChecker: + enabled: false +Try: + ancestry: + LengthConstraintChecker: + enabled: false + escape_query: + ThreeStateBooleanChecker: + enabled: false + field_spec: + LengthConstraintChecker: + enabled: false + id: + PrimaryKeyTypeChecker: + enabled: false + name: + LengthConstraintChecker: + enabled: false + query_params: + LengthConstraintChecker: + enabled: false + search_endpoint: + ForeignKeyChecker: + enabled: false +User: + administrator: + ThreeStateBooleanChecker: + enabled: false + agreed: + ThreeStateBooleanChecker: + enabled: false + announcements: + MissingIndexChecker: + enabled: true + api_keys: + MissingIndexChecker: + enabled: true + books: + MissingIndexChecker: + enabled: true + cases: + ForeignKeyCascadeChecker: + enabled: false + company: + LengthConstraintChecker: + enabled: false + email: + ColumnPresenceChecker: + enabled: false + LengthConstraintChecker: + enabled: false + id: + PrimaryKeyTypeChecker: + enabled: false + index_users_on_invitation_token: + UniqueIndexChecker: + enabled: false + index_users_on_reset_password_token: + UniqueIndexChecker: + enabled: false + invitation_token: + LengthConstraintChecker: + enabled: false + invited_by: + ForeignKeyChecker: + enabled: false + locked: + ThreeStateBooleanChecker: + enabled: false + name: + LengthConstraintChecker: + enabled: false + owned_scorers: + MissingIndexChecker: + enabled: true + password: + ColumnPresenceChecker: + enabled: false + LengthConstraintChecker: + enabled: false + permissions: + MissingIndexChecker: + enabled: true + profile_pic: + LengthConstraintChecker: + enabled: false + reset_password_token: + LengthConstraintChecker: + enabled: false + stored_raw_invitation_token: + LengthConstraintChecker: + enabled: false diff --git a/.database_consistency.yml b/.database_consistency.yml new file mode 100644 index 000000000..ec1cd6055 --- /dev/null +++ b/.database_consistency.yml @@ -0,0 +1,9 @@ +# Ignore false positive from Rails' ActionText and ActiveStorage +ActionText::RichText: + enabled: false +ActiveStorage::Attachment: + enabled: false +ActiveStorage::Blob: + enabled: false +ActiveStorage::VariantRecord: + enabled: false From c8b468ae8df135932e9bdd82028d8175bc0313d8 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Fri, 10 Jan 2025 08:41:04 -0500 Subject: [PATCH 4/7] Flip MissingIndexChecker to true --- .../20250110133600_add_announcements_author_id_index.rb | 5 +++++ db/migrate/20250110133916_add_api_keys_user_id_index.rb | 5 +++++ db/migrate/20250110133917_add_books_owner_id_index.rb | 5 +++++ db/migrate/20250110133953_add_cases_book_id_index.rb | 5 +++++ ...10133954_add_announcement_viewed_announcement_id_index.rb | 5 +++++ db/migrate/20250110133955_add_scorers_owner_id_index.rb | 5 +++++ db/migrate/20250110133956_add_permissions_user_id_index.rb | 5 +++++ 7 files changed, 35 insertions(+) create mode 100644 db/migrate/20250110133600_add_announcements_author_id_index.rb create mode 100644 db/migrate/20250110133916_add_api_keys_user_id_index.rb create mode 100644 db/migrate/20250110133917_add_books_owner_id_index.rb create mode 100644 db/migrate/20250110133953_add_cases_book_id_index.rb create mode 100644 db/migrate/20250110133954_add_announcement_viewed_announcement_id_index.rb create mode 100644 db/migrate/20250110133955_add_scorers_owner_id_index.rb create mode 100644 db/migrate/20250110133956_add_permissions_user_id_index.rb diff --git a/db/migrate/20250110133600_add_announcements_author_id_index.rb b/db/migrate/20250110133600_add_announcements_author_id_index.rb new file mode 100644 index 000000000..d548ef793 --- /dev/null +++ b/db/migrate/20250110133600_add_announcements_author_id_index.rb @@ -0,0 +1,5 @@ +class AddAnnouncementsAuthorIdIndex < ActiveRecord::Migration[8.0] + def change + add_index :announcements, :author_id, name: :index_announcements_author_id + end +end diff --git a/db/migrate/20250110133916_add_api_keys_user_id_index.rb b/db/migrate/20250110133916_add_api_keys_user_id_index.rb new file mode 100644 index 000000000..42e7ea579 --- /dev/null +++ b/db/migrate/20250110133916_add_api_keys_user_id_index.rb @@ -0,0 +1,5 @@ +class AddApiKeysUserIdIndex < ActiveRecord::Migration[8.0] + def change + add_index :api_keys, :user_id, name: :index_api_keys_user_id + end +end diff --git a/db/migrate/20250110133917_add_books_owner_id_index.rb b/db/migrate/20250110133917_add_books_owner_id_index.rb new file mode 100644 index 000000000..ab63e7d9d --- /dev/null +++ b/db/migrate/20250110133917_add_books_owner_id_index.rb @@ -0,0 +1,5 @@ +class AddBooksOwnerIdIndex < ActiveRecord::Migration[8.0] + def change + add_index :books, :owner_id, name: :index_books_owner_id + end +end diff --git a/db/migrate/20250110133953_add_cases_book_id_index.rb b/db/migrate/20250110133953_add_cases_book_id_index.rb new file mode 100644 index 000000000..6345c4512 --- /dev/null +++ b/db/migrate/20250110133953_add_cases_book_id_index.rb @@ -0,0 +1,5 @@ +class AddCasesBookIdIndex < ActiveRecord::Migration[8.0] + def change + add_index :cases, :book_id, name: :index_cases_book_id + end +end diff --git a/db/migrate/20250110133954_add_announcement_viewed_announcement_id_index.rb b/db/migrate/20250110133954_add_announcement_viewed_announcement_id_index.rb new file mode 100644 index 000000000..1ea57cc27 --- /dev/null +++ b/db/migrate/20250110133954_add_announcement_viewed_announcement_id_index.rb @@ -0,0 +1,5 @@ +class AddAnnouncementViewedAnnouncementIdIndex < ActiveRecord::Migration[8.0] + def change + add_index :announcement_viewed, :announcement_id, name: :index_announcement_viewed_announcement_id + end +end diff --git a/db/migrate/20250110133955_add_scorers_owner_id_index.rb b/db/migrate/20250110133955_add_scorers_owner_id_index.rb new file mode 100644 index 000000000..49fe150fe --- /dev/null +++ b/db/migrate/20250110133955_add_scorers_owner_id_index.rb @@ -0,0 +1,5 @@ +class AddScorersOwnerIdIndex < ActiveRecord::Migration[8.0] + def change + add_index :scorers, :owner_id, name: :index_scorers_owner_id + end +end diff --git a/db/migrate/20250110133956_add_permissions_user_id_index.rb b/db/migrate/20250110133956_add_permissions_user_id_index.rb new file mode 100644 index 000000000..8a5d09c8b --- /dev/null +++ b/db/migrate/20250110133956_add_permissions_user_id_index.rb @@ -0,0 +1,5 @@ +class AddPermissionsUserIdIndex < ActiveRecord::Migration[8.0] + def change + add_index :permissions, :user_id, name: :index_permissions_user_id + end +end From 227ebcdd3734d9e0b771d68c6a04acaac7e5640f Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Fri, 10 Jan 2025 09:37:37 -0500 Subject: [PATCH 5/7] Add last MissingIndexChecker flip and annotations. --- .database_consistency.todo.yml | 2 +- app/models/announcement.rb | 4 ++++ app/models/announcement_viewed.rb | 4 ++++ app/models/api_key.rb | 1 + app/models/book.rb | 1 + app/models/case.rb | 3 ++- app/models/permission.rb | 4 ++++ app/models/score.rb | 1 + app/models/scorer.rb | 4 ++++ ...250110143216_add_case_scores_annotation_id_index.rb | 5 +++++ db/schema.rb | 10 +++++++++- test/fixtures/announcements.yml | 4 ++++ test/fixtures/books.yml | 1 + test/fixtures/cases.yml | 3 ++- test/fixtures/scorers.yml | 4 ++++ test/fixtures/scores.yml | 1 + test/models/announcement_test.rb | 4 ++++ test/models/book_test.rb | 1 + test/models/case_test.rb | 3 ++- test/models/permission_test.rb | 4 ++++ test/models/score_test.rb | 1 + test/models/scorer_test.rb | 4 ++++ 22 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20250110143216_add_case_scores_annotation_id_index.rb diff --git a/.database_consistency.todo.yml b/.database_consistency.todo.yml index 609cba2cb..dbc055242 100644 --- a/.database_consistency.todo.yml +++ b/.database_consistency.todo.yml @@ -90,7 +90,7 @@ Annotation: enabled: false score: MissingIndexChecker: - enabled: false + enabled: true source: LengthConstraintChecker: enabled: false diff --git a/app/models/announcement.rb b/app/models/announcement.rb index a96654864..95ce46748 100644 --- a/app/models/announcement.rb +++ b/app/models/announcement.rb @@ -11,6 +11,10 @@ # updated_at :datetime not null # author_id :integer # +# Indexes +# +# index_announcements_author_id (author_id) +# class Announcement < ApplicationRecord belongs_to :author, class_name: 'User' has_many :announcement_viewed, dependent: :destroy diff --git a/app/models/announcement_viewed.rb b/app/models/announcement_viewed.rb index c87e25c8c..55ca5a0f1 100644 --- a/app/models/announcement_viewed.rb +++ b/app/models/announcement_viewed.rb @@ -10,6 +10,10 @@ # announcement_id :integer # user_id :integer # +# Indexes +# +# index_announcement_viewed_announcement_id (announcement_id) +# class AnnouncementViewed < ApplicationRecord self.table_name = 'announcement_viewed' belongs_to :user diff --git a/app/models/api_key.rb b/app/models/api_key.rb index 496e34235..bba02045a 100644 --- a/app/models/api_key.rb +++ b/app/models/api_key.rb @@ -13,6 +13,7 @@ # Indexes # # index_api_keys_on_token_digest (token_digest) +# index_api_keys_user_id (user_id) # class ApiKey < ApplicationRecord HMAC_SECRET_KEY = Rails.application.secret_key_base diff --git a/app/models/book.rb b/app/models/book.rb index a53beaa6d..07a478671 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -20,6 +20,7 @@ # Indexes # # index_books_on_selection_strategy_id (selection_strategy_id) +# index_books_owner_id (owner_id) # # Foreign Keys # diff --git a/app/models/case.rb b/app/models/case.rb index be05d0686..3d5dec43a 100644 --- a/app/models/case.rb +++ b/app/models/case.rb @@ -21,7 +21,8 @@ # # Indexes # -# user_id (owner_id) +# index_cases_book_id (book_id) +# user_id (owner_id) # # Foreign Keys # diff --git a/app/models/permission.rb b/app/models/permission.rb index 11053ed54..2195cd55d 100644 --- a/app/models/permission.rb +++ b/app/models/permission.rb @@ -12,6 +12,10 @@ # updated_at :datetime not null # user_id :integer # +# Indexes +# +# index_permissions_user_id (user_id) +# class Permission < ApplicationRecord # Associations diff --git a/app/models/score.rb b/app/models/score.rb index f7e84e171..c88ffd01f 100644 --- a/app/models/score.rb +++ b/app/models/score.rb @@ -18,6 +18,7 @@ # Indexes # # case_id (case_id) +# index_case_scores_annotation_id (annotation_id) UNIQUE # index_case_scores_on_annotation_id (annotation_id) # support_last_score (updated_at,created_at,id) # user_id (user_id) diff --git a/app/models/scorer.rb b/app/models/scorer.rb index e166b3b1b..69e31bd78 100644 --- a/app/models/scorer.rb +++ b/app/models/scorer.rb @@ -15,6 +15,10 @@ # updated_at :datetime not null # owner_id :integer # +# Indexes +# +# index_scorers_owner_id (owner_id) +# require 'scale_serializer' diff --git a/db/migrate/20250110143216_add_case_scores_annotation_id_index.rb b/db/migrate/20250110143216_add_case_scores_annotation_id_index.rb new file mode 100644 index 000000000..5a5fc44b5 --- /dev/null +++ b/db/migrate/20250110143216_add_case_scores_annotation_id_index.rb @@ -0,0 +1,5 @@ +class AddCaseScoresAnnotationIdIndex < ActiveRecord::Migration[8.0] + def change + add_index :case_scores, :annotation_id, name: :index_case_scores_annotation_id, unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 878471aa8..27ff1c2f2 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[8.0].define(version: 2025_01_08_171851) do +ActiveRecord::Schema[8.0].define(version: 2025_01_10_143216) do create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_bin", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false @@ -102,6 +102,7 @@ t.integer "user_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["announcement_id"], name: "index_announcement_viewed_announcement_id" end create_table "announcements", charset: "utf8mb4", collation: "utf8mb4_bin", force: :cascade do |t| @@ -110,6 +111,7 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.boolean "live", default: false + t.index ["author_id"], name: "index_announcements_author_id" end create_table "api_keys", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| @@ -118,6 +120,7 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["token_digest"], name: "index_api_keys_on_token_digest" + t.index ["user_id"], name: "index_api_keys_user_id" end create_table "blazer_audits", charset: "utf8mb4", collation: "utf8mb4_bin", force: :cascade do |t| @@ -196,6 +199,7 @@ t.string "export_job" t.string "import_job" t.string "populate_job" + t.index ["owner_id"], name: "index_books_owner_id" t.index ["selection_strategy_id"], name: "index_books_on_selection_strategy_id" end @@ -217,6 +221,7 @@ t.binary "queries", size: :medium t.integer "annotation_id" t.datetime "updated_at", precision: nil + t.index ["annotation_id"], name: "index_case_scores_annotation_id", unique: true t.index ["annotation_id"], name: "index_case_scores_on_annotation_id" t.index ["case_id"], name: "case_id" t.index ["updated_at", "created_at", "id"], name: "support_last_score" @@ -235,6 +240,7 @@ t.boolean "public" t.json "options" t.boolean "nightly" + t.index ["book_id"], name: "index_cases_book_id" t.index ["owner_id"], name: "user_id" end @@ -267,6 +273,7 @@ t.boolean "on", default: false t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false + t.index ["user_id"], name: "index_permissions_user_id" end create_table "queries", id: :integer, charset: "utf8mb3", force: :cascade do |t| @@ -317,6 +324,7 @@ t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false t.boolean "communal", default: false + t.index ["owner_id"], name: "index_scorers_owner_id" end create_table "search_endpoints", charset: "utf8mb3", force: :cascade do |t| diff --git a/test/fixtures/announcements.yml b/test/fixtures/announcements.yml index b4cdf82fe..7a5b8fc38 100644 --- a/test/fixtures/announcements.yml +++ b/test/fixtures/announcements.yml @@ -9,6 +9,10 @@ # updated_at :datetime not null # author_id :integer # +# Indexes +# +# index_announcements_author_id (author_id) +# live_announcement: text: We have a new Scorer! 🥳 diff --git a/test/fixtures/books.yml b/test/fixtures/books.yml index 426f33fb1..64edba1df 100644 --- a/test/fixtures/books.yml +++ b/test/fixtures/books.yml @@ -18,6 +18,7 @@ # Indexes # # index_books_on_selection_strategy_id (selection_strategy_id) +# index_books_owner_id (owner_id) # # Foreign Keys # diff --git a/test/fixtures/cases.yml b/test/fixtures/cases.yml index 7c5087fb9..a250b5101 100644 --- a/test/fixtures/cases.yml +++ b/test/fixtures/cases.yml @@ -17,7 +17,8 @@ # # Indexes # -# user_id (owner_id) +# index_cases_book_id (book_id) +# user_id (owner_id) # # Foreign Keys # diff --git a/test/fixtures/scorers.yml b/test/fixtures/scorers.yml index 13577f6e3..0f6a84dda 100644 --- a/test/fixtures/scorers.yml +++ b/test/fixtures/scorers.yml @@ -20,6 +20,10 @@ # updated_at :datetime not null # owner_id :integer # +# Indexes +# +# index_scorers_owner_id (owner_id) +# quepid_default_scorer: code: pass(); diff --git a/test/fixtures/scores.yml b/test/fixtures/scores.yml index 847fb2573..6d0be02d7 100644 --- a/test/fixtures/scores.yml +++ b/test/fixtures/scores.yml @@ -16,6 +16,7 @@ # Indexes # # case_id (case_id) +# index_case_scores_annotation_id (annotation_id) UNIQUE # index_case_scores_on_annotation_id (annotation_id) # support_last_score (updated_at,created_at,id) # user_id (user_id) diff --git a/test/models/announcement_test.rb b/test/models/announcement_test.rb index b37613352..7cf997ed8 100644 --- a/test/models/announcement_test.rb +++ b/test/models/announcement_test.rb @@ -11,6 +11,10 @@ # updated_at :datetime not null # author_id :integer # +# Indexes +# +# index_announcements_author_id (author_id) +# require 'test_helper' class AnnouncementTest < ActiveSupport::TestCase diff --git a/test/models/book_test.rb b/test/models/book_test.rb index 6334f13e6..a405ccca6 100644 --- a/test/models/book_test.rb +++ b/test/models/book_test.rb @@ -20,6 +20,7 @@ # Indexes # # index_books_on_selection_strategy_id (selection_strategy_id) +# index_books_owner_id (owner_id) # # Foreign Keys # diff --git a/test/models/case_test.rb b/test/models/case_test.rb index c63158bef..6f7cff575 100644 --- a/test/models/case_test.rb +++ b/test/models/case_test.rb @@ -19,7 +19,8 @@ # # Indexes # -# user_id (owner_id) +# index_cases_book_id (book_id) +# user_id (owner_id) # # Foreign Keys # diff --git a/test/models/permission_test.rb b/test/models/permission_test.rb index f58e12c38..b84be82fe 100644 --- a/test/models/permission_test.rb +++ b/test/models/permission_test.rb @@ -12,6 +12,10 @@ # updated_at :datetime not null # user_id :integer # +# Indexes +# +# index_permissions_user_id (user_id) +# require 'test_helper' diff --git a/test/models/score_test.rb b/test/models/score_test.rb index 7f1ea2b8d..ad815b661 100644 --- a/test/models/score_test.rb +++ b/test/models/score_test.rb @@ -18,6 +18,7 @@ # Indexes # # case_id (case_id) +# index_case_scores_annotation_id (annotation_id) UNIQUE # index_case_scores_on_annotation_id (annotation_id) # support_last_score (updated_at,created_at,id) # user_id (user_id) diff --git a/test/models/scorer_test.rb b/test/models/scorer_test.rb index ff61bbbc2..3216c3a6c 100644 --- a/test/models/scorer_test.rb +++ b/test/models/scorer_test.rb @@ -15,6 +15,10 @@ # updated_at :datetime not null # owner_id :integer # +# Indexes +# +# index_scorers_owner_id (owner_id) +# require 'test_helper' From a3372e62045e5dcfe12efdb0568f9f0c4831f485 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Fri, 10 Jan 2025 11:20:56 -0500 Subject: [PATCH 6/7] Ignore these gem related fields --- .database_consistency.todo.yml | 82 ---------------------------------- .database_consistency.yml | 4 ++ 2 files changed, 4 insertions(+), 82 deletions(-) diff --git a/.database_consistency.todo.yml b/.database_consistency.todo.yml index dbc055242..1b15fcdd2 100644 --- a/.database_consistency.todo.yml +++ b/.database_consistency.todo.yml @@ -1,86 +1,4 @@ --- -Ahoy::Event: - name: - LengthConstraintChecker: - enabled: false - user: - ForeignKeyChecker: - enabled: false - visit: - ColumnPresenceChecker: - enabled: false - ForeignKeyChecker: - enabled: false -Ahoy::Visit: - app_version: - LengthConstraintChecker: - enabled: false - browser: - LengthConstraintChecker: - enabled: false - city: - LengthConstraintChecker: - enabled: false - country: - LengthConstraintChecker: - enabled: false - device_type: - LengthConstraintChecker: - enabled: false - index_ahoy_visits_on_visit_token: - UniqueIndexChecker: - enabled: false - ip: - LengthConstraintChecker: - enabled: false - landing_page: - LengthConstraintChecker: - enabled: false - os: - LengthConstraintChecker: - enabled: false - os_version: - LengthConstraintChecker: - enabled: false - platform: - LengthConstraintChecker: - enabled: false - referrer: - LengthConstraintChecker: - enabled: false - referring_domain: - LengthConstraintChecker: - enabled: false - region: - LengthConstraintChecker: - enabled: false - user: - ForeignKeyChecker: - enabled: false - user_agent: - LengthConstraintChecker: - enabled: false - utm_campaign: - LengthConstraintChecker: - enabled: false - utm_content: - LengthConstraintChecker: - enabled: false - utm_medium: - LengthConstraintChecker: - enabled: false - utm_source: - LengthConstraintChecker: - enabled: false - utm_term: - LengthConstraintChecker: - enabled: false - visit_token: - LengthConstraintChecker: - enabled: false - visitor_token: - LengthConstraintChecker: - enabled: false Annotation: id: PrimaryKeyTypeChecker: diff --git a/.database_consistency.yml b/.database_consistency.yml index ec1cd6055..a61683c89 100644 --- a/.database_consistency.yml +++ b/.database_consistency.yml @@ -7,3 +7,7 @@ ActiveStorage::Blob: enabled: false ActiveStorage::VariantRecord: enabled: false +Ahoy::Event: + enabled: false +Ahoy::Visit: + enabled: false From f1d7f591d889a066f9cc820bb6e19ade0db7196d Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Fri, 10 Jan 2025 11:22:02 -0500 Subject: [PATCH 7/7] Resolve RedundantIndexChecker on score --- app/models/score.rb | 9 ++++----- ...59_remove_index_case_scores_on_annotation_id_index.rb | 5 +++++ db/schema.rb | 3 +-- test/fixtures/scores.yml | 9 ++++----- test/models/score_test.rb | 9 ++++----- 5 files changed, 18 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20250110161959_remove_index_case_scores_on_annotation_id_index.rb diff --git a/app/models/score.rb b/app/models/score.rb index c88ffd01f..298ed52b1 100644 --- a/app/models/score.rb +++ b/app/models/score.rb @@ -17,11 +17,10 @@ # # Indexes # -# case_id (case_id) -# index_case_scores_annotation_id (annotation_id) UNIQUE -# index_case_scores_on_annotation_id (annotation_id) -# support_last_score (updated_at,created_at,id) -# user_id (user_id) +# case_id (case_id) +# index_case_scores_annotation_id (annotation_id) UNIQUE +# support_last_score (updated_at,created_at,id) +# user_id (user_id) # # Foreign Keys # diff --git a/db/migrate/20250110161959_remove_index_case_scores_on_annotation_id_index.rb b/db/migrate/20250110161959_remove_index_case_scores_on_annotation_id_index.rb new file mode 100644 index 000000000..751c7a622 --- /dev/null +++ b/db/migrate/20250110161959_remove_index_case_scores_on_annotation_id_index.rb @@ -0,0 +1,5 @@ +class RemoveIndexCaseScoresOnAnnotationIdIndex < ActiveRecord::Migration[8.0] + def change + remove_index 'case_scores', name: 'index_case_scores_on_annotation_id' + end +end diff --git a/db/schema.rb b/db/schema.rb index 27ff1c2f2..6d1ac2fb7 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[8.0].define(version: 2025_01_10_143216) do +ActiveRecord::Schema[8.0].define(version: 2025_01_10_161959) do create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_bin", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false @@ -222,7 +222,6 @@ t.integer "annotation_id" t.datetime "updated_at", precision: nil t.index ["annotation_id"], name: "index_case_scores_annotation_id", unique: true - t.index ["annotation_id"], name: "index_case_scores_on_annotation_id" t.index ["case_id"], name: "case_id" t.index ["updated_at", "created_at", "id"], name: "support_last_score" t.index ["user_id"], name: "user_id" diff --git a/test/fixtures/scores.yml b/test/fixtures/scores.yml index 6d0be02d7..fce1b617f 100644 --- a/test/fixtures/scores.yml +++ b/test/fixtures/scores.yml @@ -15,11 +15,10 @@ # # Indexes # -# case_id (case_id) -# index_case_scores_annotation_id (annotation_id) UNIQUE -# index_case_scores_on_annotation_id (annotation_id) -# support_last_score (updated_at,created_at,id) -# user_id (user_id) +# case_id (case_id) +# index_case_scores_annotation_id (annotation_id) UNIQUE +# support_last_score (updated_at,created_at,id) +# user_id (user_id) # # Foreign Keys # diff --git a/test/models/score_test.rb b/test/models/score_test.rb index ad815b661..54f603a9e 100644 --- a/test/models/score_test.rb +++ b/test/models/score_test.rb @@ -17,11 +17,10 @@ # # Indexes # -# case_id (case_id) -# index_case_scores_annotation_id (annotation_id) UNIQUE -# index_case_scores_on_annotation_id (annotation_id) -# support_last_score (updated_at,created_at,id) -# user_id (user_id) +# case_id (case_id) +# index_case_scores_annotation_id (annotation_id) UNIQUE +# support_last_score (updated_at,created_at,id) +# user_id (user_id) # # Foreign Keys #