3 changed files with 44 additions and 1 deletions
@ -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 |
||||
@ -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 |
||||
Loading…
Reference in new issue