The personal finance app for everyone
Add indexes to core models (#2464)
Zach Gollwitzerd5b147f2cd6a
diff --git a/db/migrate/20250718120146_add_indexes_to_core_models.rb b/db/migrate/20250718120146_add_indexes_to_core_models.rbnew file mode 100644index 00000000..bac38c8c--- /dev/null+++ b/db/migrate/20250718120146_add_indexes_to_core_models.rb@@ -0,0 +1,20 @@+class AddIndexesToCoreModels < ActiveRecord::Migration[7.2]+ def change+ # Accounts table indexes+ add_index :accounts, [ :family_id, :status ]+ add_index :accounts, :status+ add_index :accounts, :currency++ # Balances table indexes+ add_index :balances, [ :account_id, :date ], order: { date: :desc }++ # Entries table indexes+ add_index :entries, [ :account_id, :date ]+ add_index :entries, :date+ add_index :entries, :entryable_type+ add_index :entries, "lower(name)", name: "index_entries_on_lower_name"++ # Transfers table indexes+ add_index :transfers, :status+ end+enddiff --git a/db/schema.rb b/db/schema.rbindex 56d7ba09..3b839c95 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[7.2].define(version: 2025_07_10_225721) do+ActiveRecord::Schema[7.2].define(version: 2025_07_18_120146) do# These are extensions that must be enabled in order to support this databaseenable_extension "pgcrypto"enable_extension "plpgsql"@@ -37,11 +37,14 @@ ActiveRecord::Schema[7.2].define(version: 2025_07_10_225721) dot.string "status", default: "active"t.index ["accountable_id", "accountable_type"], name: "index_accounts_on_accountable_id_and_accountable_type"t.index ["accountable_type"], name: "index_accounts_on_accountable_type"+ t.index ["currency"], name: "index_accounts_on_currency"t.index ["family_id", "accountable_type"], name: "index_accounts_on_family_id_and_accountable_type"t.index ["family_id", "id"], name: "index_accounts_on_family_id_and_id"+ t.index ["family_id", "status"], name: "index_accounts_on_family_id_and_status"t.index ["family_id"], name: "index_accounts_on_family_id"t.index ["import_id"], name: "index_accounts_on_import_id"t.index ["plaid_account_id"], name: "index_accounts_on_plaid_account_id"+ t.index ["status"], name: "index_accounts_on_status"endcreate_table "active_storage_attachments", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|@@ -113,6 +116,7 @@ ActiveRecord::Schema[7.2].define(version: 2025_07_10_225721) dot.datetime "updated_at", null: falset.decimal "cash_balance", precision: 19, scale: 4, default: "0.0"t.index ["account_id", "date", "currency"], name: "index_account_balances_on_account_id_date_currency_unique", unique: true+ t.index ["account_id", "date"], name: "index_balances_on_account_id_and_date", order: { date: :desc }t.index ["account_id"], name: "index_balances_on_account_id"end@@ -215,7 +219,11 @@ ActiveRecord::Schema[7.2].define(version: 2025_07_10_225721) dot.boolean "excluded", default: falset.string "plaid_id"t.jsonb "locked_attributes", default: {}+ t.index "lower((name)::text)", name: "index_entries_on_lower_name"+ t.index ["account_id", "date"], name: "index_entries_on_account_id_and_date"t.index ["account_id"], name: "index_entries_on_account_id"+ t.index ["date"], name: "index_entries_on_date"+ t.index ["entryable_type"], name: "index_entries_on_entryable_type"t.index ["import_id"], name: "index_entries_on_import_id"end@@ -741,6 +749,7 @@ ActiveRecord::Schema[7.2].define(version: 2025_07_10_225721) dot.index ["inflow_transaction_id", "outflow_transaction_id"], name: "idx_on_inflow_transaction_id_outflow_transaction_id_8cd07a28bd", unique: truet.index ["inflow_transaction_id"], name: "index_transfers_on_inflow_transaction_id"t.index ["outflow_transaction_id"], name: "index_transfers_on_outflow_transaction_id"+ t.index ["status"], name: "index_transfers_on_status"endcreate_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|