diff --git a/db/migrate/20241002014059_add_index_on_order_cycles_orders_open_at_and_orders_close_at.rb b/db/migrate/20241002014059_add_index_on_order_cycles_orders_open_at_and_orders_close_at.rb new file mode 100644 index 0000000000..6b2c28789f --- /dev/null +++ b/db/migrate/20241002014059_add_index_on_order_cycles_orders_open_at_and_orders_close_at.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +# We use these fields a lot to find open order cycles. +# Adding indexes seems obvious but I couldn't observe any performance gain. +# I also couldn't observe any harm. So adding these indexes will avoid any +# further investigation in the future. It's done. +class AddIndexOnOrderCyclesOrdersOpenAtAndOrdersCloseAt < ActiveRecord::Migration[7.0] + def change + add_index :order_cycles, :orders_open_at + add_index :order_cycles, :orders_close_at + end +end diff --git a/db/schema.rb b/db/schema.rb index c398b00eb3..9ca97c3eef 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.0].define(version: 2024_08_28_203544) do +ActiveRecord::Schema[7.0].define(version: 2024_10_02_014059) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" enable_extension "plpgsql" @@ -338,6 +338,8 @@ ActiveRecord::Schema[7.0].define(version: 2024_08_28_203544) do t.boolean "automatic_notifications", default: false t.boolean "mails_sent", default: false t.datetime "opened_at", precision: nil + t.index ["orders_close_at"], name: "index_order_cycles_on_orders_close_at" + t.index ["orders_open_at"], name: "index_order_cycles_on_orders_open_at" end create_table "order_cycles_distributor_payment_methods", id: false, force: :cascade do |t|