diff --git a/.rubocop.yml b/.rubocop.yml index 250f2c94b..a25d82f05 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -208,6 +208,9 @@ Performance/Sum: Rails/ActiveRecordCallbacksOrder: Enabled: true +Rails/AddColumnIndex: + Enabled: true + Rails/CreateTableWithTimestamps: Enabled: true Exclude: diff --git a/db/migrate/20151028145921_add_confidence_score_to_comments.rb b/db/migrate/20151028145921_add_confidence_score_to_comments.rb index 540eff133..ff64b9ef7 100644 --- a/db/migrate/20151028145921_add_confidence_score_to_comments.rb +++ b/db/migrate/20151028145921_add_confidence_score_to_comments.rb @@ -1,5 +1,5 @@ class AddConfidenceScoreToComments < ActiveRecord::Migration[4.2] def change - add_column :comments, :confidence_score, :integer, index: true + add_column :comments, :confidence_score, :integer end end diff --git a/db/migrate/20160411161531_add_genre_and_dob_to_users.rb b/db/migrate/20160411161531_add_genre_and_dob_to_users.rb index 59411ca7e..8b623b35e 100644 --- a/db/migrate/20160411161531_add_genre_and_dob_to_users.rb +++ b/db/migrate/20160411161531_add_genre_and_dob_to_users.rb @@ -1,6 +1,6 @@ class AddGenreAndDobToUsers < ActiveRecord::Migration[4.2] def change - add_column :users, :genre, :string, index: true, limit: 10 - add_column :users, :date_of_birth, :datetime, index: true + add_column :users, :genre, :string, limit: 10 + add_column :users, :date_of_birth, :datetime end end diff --git a/db/migrate/20160610094658_desnormalize_ballot_line.rb b/db/migrate/20160610094658_desnormalize_ballot_line.rb index afbf85484..71c9556a3 100644 --- a/db/migrate/20160610094658_desnormalize_ballot_line.rb +++ b/db/migrate/20160610094658_desnormalize_ballot_line.rb @@ -1,7 +1,7 @@ class DesnormalizeBallotLine < ActiveRecord::Migration[4.2] def change - add_column :budget_ballot_lines, :budget_id, :integer, index: true - add_column :budget_ballot_lines, :group_id, :integer, index: true - add_column :budget_ballot_lines, :heading_id, :integer, index: true + add_column :budget_ballot_lines, :budget_id, :integer + add_column :budget_ballot_lines, :group_id, :integer + add_column :budget_ballot_lines, :heading_id, :integer end end diff --git a/db/migrate/20160905092539_denormalize_investments.rb b/db/migrate/20160905092539_denormalize_investments.rb index bed96e1d1..43a75f807 100644 --- a/db/migrate/20160905092539_denormalize_investments.rb +++ b/db/migrate/20160905092539_denormalize_investments.rb @@ -1,6 +1,6 @@ class DenormalizeInvestments < ActiveRecord::Migration[4.2] def change - add_column :budget_investments, :budget_id, :integer, index: true - add_column :budget_investments, :group_id, :integer, index: true + add_column :budget_investments, :budget_id, :integer + add_column :budget_investments, :group_id, :integer end end diff --git a/db/migrate/20161221172447_add_selected_to_budget_investment.rb b/db/migrate/20161221172447_add_selected_to_budget_investment.rb index 7f4f9bd91..d99dc669f 100644 --- a/db/migrate/20161221172447_add_selected_to_budget_investment.rb +++ b/db/migrate/20161221172447_add_selected_to_budget_investment.rb @@ -1,5 +1,5 @@ class AddSelectedToBudgetInvestment < ActiveRecord::Migration[4.2] def change - add_column :budget_investments, :selected, :bool, default: false, index: true + add_column :budget_investments, :selected, :bool, default: false end end diff --git a/db/migrate/20170120161058_add_geozone_restricted_to_polls.rb b/db/migrate/20170120161058_add_geozone_restricted_to_polls.rb index 89afbafad..363a60ecb 100644 --- a/db/migrate/20170120161058_add_geozone_restricted_to_polls.rb +++ b/db/migrate/20170120161058_add_geozone_restricted_to_polls.rb @@ -1,5 +1,5 @@ class AddGeozoneRestrictedToPolls < ActiveRecord::Migration[4.2] def change - add_column :polls, :geozone_restricted, :boolean, default: false, index: true + add_column :polls, :geozone_restricted, :boolean, default: false end end diff --git a/db/migrate/20170208110146_add_officer_id_to_failed_census_calls.rb b/db/migrate/20170208110146_add_officer_id_to_failed_census_calls.rb index a7c73528b..b3561804e 100644 --- a/db/migrate/20170208110146_add_officer_id_to_failed_census_calls.rb +++ b/db/migrate/20170208110146_add_officer_id_to_failed_census_calls.rb @@ -1,6 +1,6 @@ class AddOfficerIdToFailedCensusCalls < ActiveRecord::Migration[4.2] def change - add_column :failed_census_calls, :poll_officer_id, :integer, index: true + add_column :failed_census_calls, :poll_officer_id, :integer add_foreign_key :failed_census_calls, :poll_officers end end diff --git a/db/migrate/20170703120055_add_incompatible_to_budget_investments.rb b/db/migrate/20170703120055_add_incompatible_to_budget_investments.rb index 64fc1dc56..64d484d6f 100644 --- a/db/migrate/20170703120055_add_incompatible_to_budget_investments.rb +++ b/db/migrate/20170703120055_add_incompatible_to_budget_investments.rb @@ -1,5 +1,5 @@ class AddIncompatibleToBudgetInvestments < ActiveRecord::Migration[4.2] def change - add_column :budget_investments, :incompatible, :bool, default: false, index: true + add_column :budget_investments, :incompatible, :bool, default: false end end diff --git a/db/migrate/20190410132842_add_selected_to_proposal.rb b/db/migrate/20190410132842_add_selected_to_proposal.rb index 3a20fefbf..67067883b 100644 --- a/db/migrate/20190410132842_add_selected_to_proposal.rb +++ b/db/migrate/20190410132842_add_selected_to_proposal.rb @@ -1,5 +1,5 @@ class AddSelectedToProposal < ActiveRecord::Migration[4.2] def change - add_column :proposals, :selected, :bool, default: false, index: true + add_column :proposals, :selected, :bool, default: false end end diff --git a/db/migrate/20210811195800_add_missing_indexes.rb b/db/migrate/20210811195800_add_missing_indexes.rb new file mode 100644 index 000000000..b82aaffad --- /dev/null +++ b/db/migrate/20210811195800_add_missing_indexes.rb @@ -0,0 +1,17 @@ +class AddMissingIndexes < ActiveRecord::Migration[5.2] + def change + add_index :comments, :confidence_score + add_index :users, :gender + add_index :users, :date_of_birth + add_index :budget_ballot_lines, :budget_id + add_index :budget_ballot_lines, :group_id + add_index :budget_ballot_lines, :heading_id + add_index :budget_investments, :budget_id + add_index :budget_investments, :group_id + add_index :budget_investments, :selected + add_index :polls, :geozone_restricted + add_index :failed_census_calls, :poll_officer_id + add_index :budget_investments, :incompatible + add_index :proposals, :selected + end +end diff --git a/db/schema.rb b/db/schema.rb index d02fe0d92..ab95ffdfc 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: 2021_05_19_115700) do +ActiveRecord::Schema.define(version: 2021_08_11_195800) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" @@ -155,6 +155,9 @@ ActiveRecord::Schema.define(version: 2021_05_19_115700) do t.integer "heading_id" t.index ["ballot_id", "investment_id"], name: "index_budget_ballot_lines_on_ballot_id_and_investment_id", unique: true t.index ["ballot_id"], name: "index_budget_ballot_lines_on_ballot_id" + t.index ["budget_id"], name: "index_budget_ballot_lines_on_budget_id" + t.index ["group_id"], name: "index_budget_ballot_lines_on_group_id" + t.index ["heading_id"], name: "index_budget_ballot_lines_on_heading_id" t.index ["investment_id"], name: "index_budget_ballot_lines_on_investment_id" end @@ -274,8 +277,12 @@ ActiveRecord::Schema.define(version: 2021_05_19_115700) do t.integer "original_heading_id" t.index ["administrator_id"], name: "index_budget_investments_on_administrator_id" t.index ["author_id"], name: "index_budget_investments_on_author_id" + t.index ["budget_id"], name: "index_budget_investments_on_budget_id" t.index ["community_id"], name: "index_budget_investments_on_community_id" + t.index ["group_id"], name: "index_budget_investments_on_group_id" t.index ["heading_id"], name: "index_budget_investments_on_heading_id" + t.index ["incompatible"], name: "index_budget_investments_on_incompatible" + t.index ["selected"], name: "index_budget_investments_on_selected" t.index ["tsv"], name: "index_budget_investments_on_tsv", using: :gin end @@ -424,6 +431,7 @@ ActiveRecord::Schema.define(version: 2021_05_19_115700) do t.index ["cached_votes_total"], name: "index_comments_on_cached_votes_total" t.index ["cached_votes_up"], name: "index_comments_on_cached_votes_up" t.index ["commentable_id", "commentable_type"], name: "index_comments_on_commentable_id_and_commentable_type" + t.index ["confidence_score"], name: "index_comments_on_confidence_score" t.index ["hidden_at"], name: "index_comments_on_hidden_at" t.index ["user_id"], name: "index_comments_on_user_id" t.index ["valuation"], name: "index_comments_on_valuation" @@ -570,6 +578,7 @@ ActiveRecord::Schema.define(version: 2021_05_19_115700) do t.string "district_code" t.integer "poll_officer_id" t.integer "year_of_birth" + t.index ["poll_officer_id"], name: "index_failed_census_calls_on_poll_officer_id" t.index ["user_id"], name: "index_failed_census_calls_on_user_id" end @@ -1203,6 +1212,7 @@ ActiveRecord::Schema.define(version: 2021_05_19_115700) do t.integer "related_id" t.tsvector "tsv" t.index ["budget_id"], name: "index_polls_on_budget_id", unique: true + t.index ["geozone_restricted"], name: "index_polls_on_geozone_restricted" t.index ["related_type", "related_id"], name: "index_polls_on_related_type_and_related_id" t.index ["starts_at", "ends_at"], name: "index_polls_on_starts_at_and_ends_at" end @@ -1283,6 +1293,7 @@ ActiveRecord::Schema.define(version: 2021_05_19_115700) do t.index ["geozone_id"], name: "index_proposals_on_geozone_id" t.index ["hidden_at"], name: "index_proposals_on_hidden_at" t.index ["hot_score"], name: "index_proposals_on_hot_score" + t.index ["selected"], name: "index_proposals_on_selected" t.index ["tsv"], name: "index_proposals_on_tsv", using: :gin end @@ -1595,7 +1606,9 @@ ActiveRecord::Schema.define(version: 2021_05_19_115700) do t.boolean "recommended_debates", default: true t.boolean "recommended_proposals", default: true t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true + t.index ["date_of_birth"], name: "index_users_on_date_of_birth" t.index ["email"], name: "index_users_on_email", unique: true + t.index ["gender"], name: "index_users_on_gender" t.index ["geozone_id"], name: "index_users_on_geozone_id" t.index ["hidden_at"], name: "index_users_on_hidden_at" t.index ["password_changed_at"], name: "index_users_on_password_changed_at"