From 67fd8674c3ead2578d58d2d1f4e6c0879bb91c70 Mon Sep 17 00:00:00 2001 From: Andy Atkinson Date: Wed, 3 Jan 2024 15:33:23 -0600 Subject: [PATCH] Use concurrently for remove_index Present a explanation box recommending to use CONCURRENTLY with DROP INDEX. In Active Record, this requires two things: disable_ddl_transaction! once at the top of the migration file, and "algorithm: :concurrently" option added to every remove_index line Since this is a sensible default when PostgreSQL 14 or greater is in use, since it can avoid downtime from an index drop, make it the default. Remove the ability to disable it since it seems unnecessary in retrospect. Only show the explanation box and only add the option to remove_index when version 14 or greater is in use --- app/helpers/pg_hero/home_helper.rb | 10 ++++++++++ app/views/pg_hero/home/index.html.erb | 4 ++++ app/views/pg_hero/home/space.html.erb | 3 +++ lib/pghero/methods/basic.rb | 4 ++++ 4 files changed, 21 insertions(+) diff --git a/app/helpers/pg_hero/home_helper.rb b/app/helpers/pg_hero/home_helper.rb index 6caa2d4c4..afb40aedd 100644 --- a/app/helpers/pg_hero/home_helper.rb +++ b/app/helpers/pg_hero/home_helper.rb @@ -16,6 +16,15 @@ def pghero_js_value(value) json_escape(value.to_json(root: false)).html_safe end + def pghero_drop_idx_concurrently_explanation + if @database.drop_idx_concurrently_supported? + ret = "

Tip: Use CONCURRENTLY for DROP INDEX

" + ret << "" + ret.html_safe + end + end + def pghero_remove_index(query) if query[:columns] columns = query[:columns].map(&:to_sym) @@ -24,6 +33,7 @@ def pghero_remove_index(query) ret = String.new("remove_index #{query[:table].to_sym.inspect}") ret << ", name: #{(query[:name] || query[:index]).to_s.inspect}" ret << ", column: #{columns.inspect}" if columns + ret << ", algorithm: concurrently" if @database.drop_idx_concurrently_supported? ret end diff --git a/app/views/pg_hero/home/index.html.erb b/app/views/pg_hero/home/index.html.erb index dfb80ef11..7e7001aec 100644 --- a/app/views/pg_hero/home/index.html.erb +++ b/app/views/pg_hero/home/index.html.erb @@ -391,6 +391,10 @@ diff --git a/app/views/pg_hero/home/space.html.erb b/app/views/pg_hero/home/space.html.erb index 0376b291b..c74fbe9ab 100644 --- a/app/views/pg_hero/home/space.html.erb +++ b/app/views/pg_hero/home/space.html.erb @@ -31,6 +31,9 @@