From 1b83a1eaa13532d1c8d0603b5c76a258327144c1 Mon Sep 17 00:00:00 2001 From: Sascha Karnatz <122262394+sascha-karnatz@users.noreply.github.com> Date: Mon, 8 May 2023 08:54:02 +0200 Subject: [PATCH] Add indexes to pictures table The Index will prevent temp tables if the user is searching for name or file_name. This is necessary if the table becomes bigger. --- .../20230505132743_add_indexes_to_alchemy_pictures.rb | 6 ++++++ .../20230505132743_add_indexes_to_alchemy_pictures.rb | 6 ++++++ spec/dummy/db/schema.rb | 4 +++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20230505132743_add_indexes_to_alchemy_pictures.rb create mode 100644 spec/dummy/db/migrate/20230505132743_add_indexes_to_alchemy_pictures.rb diff --git a/db/migrate/20230505132743_add_indexes_to_alchemy_pictures.rb b/db/migrate/20230505132743_add_indexes_to_alchemy_pictures.rb new file mode 100644 index 0000000000..75c3ca1b9a --- /dev/null +++ b/db/migrate/20230505132743_add_indexes_to_alchemy_pictures.rb @@ -0,0 +1,6 @@ +class AddIndexesToAlchemyPictures < ActiveRecord::Migration[7.0] + def change + add_index :alchemy_pictures, :name, if_not_exists: true + add_index :alchemy_pictures, :image_file_name, if_not_exists: true + end +end diff --git a/spec/dummy/db/migrate/20230505132743_add_indexes_to_alchemy_pictures.rb b/spec/dummy/db/migrate/20230505132743_add_indexes_to_alchemy_pictures.rb new file mode 100644 index 0000000000..75c3ca1b9a --- /dev/null +++ b/spec/dummy/db/migrate/20230505132743_add_indexes_to_alchemy_pictures.rb @@ -0,0 +1,6 @@ +class AddIndexesToAlchemyPictures < ActiveRecord::Migration[7.0] + def change + add_index :alchemy_pictures, :name, if_not_exists: true + add_index :alchemy_pictures, :image_file_name, if_not_exists: true + end +end diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb index 940260db2e..e2d4aebe81 100644 --- a/spec/dummy/db/schema.rb +++ b/spec/dummy/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: 2023_01_23_105660) do +ActiveRecord::Schema[7.0].define(version: 2023_05_05_132743) do create_table "alchemy_attachments", force: :cascade do |t| t.string "name" t.string "file_name" @@ -202,6 +202,8 @@ t.integer "image_file_size" t.string "image_file_format" t.index ["creator_id"], name: "index_alchemy_pictures_on_creator_id" + t.index ["image_file_name"], name: "index_alchemy_pictures_on_image_file_name" + t.index ["name"], name: "index_alchemy_pictures_on_name" t.index ["updater_id"], name: "index_alchemy_pictures_on_updater_id" end