Browse Source

add indexes

main
Christoph Marzell 3 weeks ago
parent
commit
47b75e71cb
  1. 16
      db/migrate/20251120104335_add_useful_indexes_to_entries_and_users.rb
  2. 17
      db/migrate/20251120105001_add_performance_indexes.rb
  3. 12
      db/schema.rb

16
db/migrate/20251120104335_add_useful_indexes_to_entries_and_users.rb

@ -0,0 +1,16 @@
class AddUsefulIndexesToEntriesAndUsers < ActiveRecord::Migration[7.1]
disable_ddl_transaction! if respond_to?(:disable_ddl_transaction!) # für PostgreSQL concurrently
def change
# Einträge Tabelle
add_index :entries, :user_id, algorithm: :concurrently, if_not_exists: true
add_index :entries, :date, algorithm: :concurrently, if_not_exists: true
add_index :entries, [:praktikums_typ, :entry_art], name: 'index_entries_on_typ_and_art', algorithm: :concurrently, if_not_exists: true
add_index :entries, :kosten, algorithm: :concurrently, if_not_exists: true
add_index :entries, :start_time, algorithm: :concurrently, if_not_exists: true
add_index :entries, :end_time, algorithm: :concurrently, if_not_exists: true
# Nutzer Tabelle
add_index :users, :praepedeutikum_done, algorithm: :concurrently, if_not_exists: true
end
end

17
db/migrate/20251120105001_add_performance_indexes.rb

@ -0,0 +1,17 @@
class AddPerformanceIndexes < ActiveRecord::Migration[7.1]
def change
# Entries
add_index :entries, :user_id unless index_exists?(:entries, :user_id)
add_index :entries, [:user_id, :date] unless index_exists?(:entries, [:user_id, :date])
add_index :entries, [:user_id, :entry_art] unless index_exists?(:entries, [:user_id, :entry_art])
add_index :entries, [:user_id, :praktikums_typ] unless index_exists?(:entries, [:user_id, :praktikums_typ])
# Users (falls du häufig nach E-Mail oder Bestätigungsstatus filterst)
add_index :users, :email unless index_exists?(:users, :email)
add_index :users, :confirmation_token unless index_exists?(:users, :confirmation_token)
add_index :users, :reset_password_token unless index_exists?(:users, :reset_password_token)
# Fortbildungskosten‑Reports: Jahr extrahieren aus date
add_index :entries, "DATE_PART('year', date)", name: 'index_entries_on_year', using: :btree
end
end

12
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2025_11_18_081233) do
ActiveRecord::Schema[7.1].define(version: 2025_11_20_105001) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -30,6 +30,15 @@ ActiveRecord::Schema[7.1].define(version: 2025_11_18_081233) do
t.datetime "end_time"
t.integer "lunch_break_minutes", default: 0
t.boolean "zaehlt_als_fortbildung", default: false, null: false
t.index "date_part('year'::text, date)", name: "index_entries_on_year"
t.index ["date"], name: "index_entries_on_date"
t.index ["end_time"], name: "index_entries_on_end_time"
t.index ["kosten"], name: "index_entries_on_kosten"
t.index ["praktikums_typ", "entry_art"], name: "index_entries_on_typ_and_art"
t.index ["start_time"], name: "index_entries_on_start_time"
t.index ["user_id", "date"], name: "index_entries_on_user_id_and_date"
t.index ["user_id", "entry_art"], name: "index_entries_on_user_id_and_entry_art"
t.index ["user_id", "praktikums_typ"], name: "index_entries_on_user_id_and_praktikums_typ"
t.index ["user_id"], name: "index_entries_on_user_id"
end
@ -52,6 +61,7 @@ ActiveRecord::Schema[7.1].define(version: 2025_11_18_081233) do
t.boolean "praepedeutikum_done", default: false, null: false
t.index ["confirmation_token"], name: "index_users_on_confirmation_token"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["praepedeutikum_done"], name: "index_users_on_praepedeutikum_done"
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end

Loading…
Cancel
Save