From 5165fb638e993b4d474ef202acdeff5e0cef3670 Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Wed, 11 May 2022 15:46:49 +0300 Subject: [PATCH] FIX: Show error message if extensions cannot be created (#16719) It used to stop the db:migrate task and broke sites that are deployed in non-standard environments (using external database server or older versions). --- lib/tasks/db.rake | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 76c5284e99..dcdf90664f 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -215,7 +215,14 @@ task 'db:migrate' => ['load_config', 'environment', 'set_locale'] do |_, args| raise "Migration #{migrations.last.version} is timestamped in the future" if migrations.last.version > now_timestamp raise "Migration #{migrations.first.version} is timestamped before the epoch" if migrations.first.version < epoch_timestamp - %i[pg_trgm unaccent].each { |extension| DB.exec "CREATE EXTENSION IF NOT EXISTS #{extension}" } + %i[pg_trgm unaccent].each do |extension| + begin + DB.exec "CREATE EXTENSION IF NOT EXISTS #{extension}" + rescue => e + STDERR.puts "Cannot enable database extension #{extension}" + STDERR.puts e + end + end ActiveRecord::Tasks::DatabaseTasks.migrate