From d5b147f2cd6a64740301440d27da6a68256f10fc Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Fri, 18 Jul 2025 08:19:44 -0400 Subject: [PATCH] Add indexes to core models (#2464) * [claudesquad] update from 'add-indexes-to-core-models' on 18 Jul 25 08:03 EDT * [claudesquad] update from 'add-indexes-to-core-models' on 18 Jul 25 08:09 EDT --- ...250718120146_add_indexes_to_core_models.rb | 20 +++++++++++++++++++ db/schema.rb | 11 +++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20250718120146_add_indexes_to_core_models.rb diff --git a/db/migrate/20250718120146_add_indexes_to_core_models.rb b/db/migrate/20250718120146_add_indexes_to_core_models.rb new file mode 100644 index 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 +end diff --git a/db/schema.rb b/db/schema.rb index 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 database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -37,11 +37,14 @@ ActiveRecord::Schema[7.2].define(version: 2025_07_10_225721) do t.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" end create_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) do t.datetime "updated_at", null: false t.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) do t.boolean "excluded", default: false t.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) do t.index ["inflow_transaction_id", "outflow_transaction_id"], name: "idx_on_inflow_transaction_id_outflow_transaction_id_8cd07a28bd", unique: true t.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" end create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|