Merge branch '15296-cwl-cancel-procs' closes #15296
[arvados.git] / services / api / db / migrate / 20190523180148_add_trigram_index_for_text_search.rb
index ef8be5f92d054e299719aa150891b2a26d569faf..881350238c5ec15c204d1930dcb3f6ebcf33a43c 100644 (file)
@@ -16,6 +16,21 @@ class AddTrigramIndexForTextSearch < ActiveRecord::Migration[5.0]
   end
 
   def up
+    begin
+      execute "CREATE EXTENSION IF NOT EXISTS pg_trgm"
+    rescue ActiveRecord::StatementInvalid => e
+      puts "Cannot create the pg_trgm extension."
+      if e.cause.is_a?(PG::InsufficientPrivilege)
+        puts "The user must have a SUPERUSER role."
+      elsif e.cause.is_a?(PG::UndefinedFile)
+        puts "The postgresql-contrib package is most likely not installed."
+      else
+        puts "Unknown Error."
+      end
+      puts "Please visit https://doc.arvados.org/admin/upgrading.html for instructions on how to run this migration."
+      throw e
+    end
+
     trgm_indexes.each do |model, indx|
       execute "CREATE INDEX #{indx} ON #{model} USING gin((#{model.classify.constantize.full_text_trgm}) gin_trgm_ops)"
     end