Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Enable the pg_trgm module for all the schemas

Dombi Attila42ca7bb199f3
diff --git a/db/migrate/20230328154645_add_gin_trgm_index_on_journals_and_custom_values.rb b/db/migrate/20230328154645_add_gin_trgm_index_on_journals_and_custom_values.rb
index 2d5f706d484..4ffabf13fb7 100644
--- a/db/migrate/20230328154645_add_gin_trgm_index_on_journals_and_custom_values.rb
+++ b/db/migrate/20230328154645_add_gin_trgm_index_on_journals_and_custom_values.rb
@@ -1,5 +1,5 @@
class AddGinTrgmIndexOnJournalsAndCustomValues < ActiveRecord::Migration[7.0]
- def change
+ def up
safe_enable_pg_trgm_extension
if extensions.include?('pg_trgm')
@@ -8,10 +8,16 @@ class AddGinTrgmIndexOnJournalsAndCustomValues < ActiveRecord::Migration[7.0]
end
end
+ def down
+ remove_index(:journals, :notes, if_exists: true)
+ remove_index(:custom_values, :value, if_exists: true)
+ drop_pg_trgm_extension
+ end
+
private
def safe_enable_pg_trgm_extension
- enable_extension("pg_trgm")
+ ActiveRecord::Base.connection.execute("CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA pg_catalog;")
rescue StandardError => e
raise unless e.message =~ /pg_trgm/
@@ -30,4 +36,8 @@ class AddGinTrgmIndexOnJournalsAndCustomValues < ActiveRecord::Migration[7.0]
MESSAGE
end
+
+ def drop_pg_trgm_extension
+ ActiveRecord::Base.connection.execute("DROP EXTENSION IF EXISTS pg_trgm CASCADE;")
+ end
end