From 676112dd6ffdea54ec267cd176af74e305e6925c Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Wed, 10 Apr 2024 21:48:54 +0200 Subject: [PATCH] fix: add index to speed up query in dol archiving job --- db/migrate/20240410193614_add_partial_index_on_dol.rb | 7 +++++++ db/schema.rb | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20240410193614_add_partial_index_on_dol.rb diff --git a/db/migrate/20240410193614_add_partial_index_on_dol.rb b/db/migrate/20240410193614_add_partial_index_on_dol.rb new file mode 100644 index 000000000..180ab42fb --- /dev/null +++ b/db/migrate/20240410193614_add_partial_index_on_dol.rb @@ -0,0 +1,7 @@ +class AddPartialIndexOnDol < ActiveRecord::Migration[7.0] + disable_ddl_transaction! + + def change + add_index :dossier_operation_logs, :id, where: 'data is not null', algorithm: :concurrently + end +end diff --git a/db/schema.rb b/db/schema.rb index 2e8f741dc..c0acf3bd7 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_04_02_212902) do +ActiveRecord::Schema[7.0].define(version: 2024_04_10_193614) do # These are extensions that must be enabled in order to support this database enable_extension "pg_buffercache" enable_extension "pg_stat_statements" @@ -420,6 +420,7 @@ ActiveRecord::Schema[7.0].define(version: 2024_04_02_212902) do t.datetime "updated_at", precision: nil, null: false t.index ["bill_signature_id"], name: "index_dossier_operation_logs_on_bill_signature_id" t.index ["dossier_id"], name: "index_dossier_operation_logs_on_dossier_id" + t.index ["id"], name: "index_dossier_operation_logs_on_id", where: "(data IS NOT NULL)" t.index ["keep_until"], name: "index_dossier_operation_logs_on_keep_until" end