1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

upgrade pg_trgm from 1.1 to 1.3

This commit is contained in:
Sylvain 2020-06-29 14:40:21 +02:00
parent 8879066f95
commit 06470c1366
5 changed files with 28 additions and 2 deletions

View File

@ -2,9 +2,10 @@
# Create a PostgreSQL specific function to make pg_search gem working with fuzzystrmatch
class AddPgSearchDmetaphoneSupportFunctions < ActiveRecord::Migration[5.2]
# PostgreSQL only
def self.up
say_with_time('Adding support functions for pg_search :dmetaphone') do
execute 'CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;'
execute 'CREATE EXTENSION IF NOT EXISTS fuzzystrmatch SCHEMA public;'
execute <<~'SQL'
CREATE OR REPLACE FUNCTION pg_search_dmetaphone(text) RETURNS text LANGUAGE SQL IMMUTABLE STRICT AS $function$
SELECT array_to_string(ARRAY(SELECT dmetaphone(unnest(regexp_split_to_array($1, E'\\s+')))), ' ')

View File

@ -2,6 +2,7 @@
# Index for full-text search in projects
class AddSearchVectorToProject < ActiveRecord::Migration[5.2]
# PostgreSQL only
def self.up
add_column :projects, :search_vector, :tsvector

View File

@ -3,6 +3,7 @@
# Create a PL/pgSQL function and trigger it on records update.
# This function will update the Project::search_vector according to the saved project
class UpdateSearchVectorOfProjects < ActiveRecord::Migration[5.2]
# PostgreSQL only
def up
execute <<-SQL
CREATE OR REPLACE FUNCTION fill_search_vector_for_project() RETURNS trigger LANGUAGE plpgsql AS $$

View File

@ -0,0 +1,21 @@
# frozen_string_literal: true
# Recreate the pg_trgm extension to upgrade from v1.1 to v1.3
# This will enable the function word_similarity(text, text) for the project's full-text searches
class UpdatePgTrgm < ActiveRecord::Migration[5.2]
# PostgreSQL only
def change
say_with_time('Upgrade extension :pg_trgm') do
execute <<~SQL
DROP INDEX profiles_lower_unaccent_first_name_trgm_idx;
DROP INDEX profiles_lower_unaccent_last_name_trgm_idx;
DROP EXTENSION pg_trgm;
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE INDEX profiles_lower_unaccent_first_name_trgm_idx ON profiles
USING gin (lower(f_unaccent(first_name)) gin_trgm_ops);
CREATE INDEX profiles_lower_unaccent_last_name_trgm_idx ON profiles
USING gin (lower(f_unaccent(last_name)) gin_trgm_ops);
SQL
end
end
end

View File

@ -5616,6 +5616,8 @@ INSERT INTO "schema_migrations" (version) VALUES
('20200511075933'),
('20200622135401'),
('20200623134900'),
('20200623141305');
('20200623141305'),
('20200629114319'),
('20200629123011');