1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-11 22:24:21 +01:00
fab-manager/db/migrate/20160613093842_create_unaccent_function.rb

26 lines
999 B
Ruby

class CreateUnaccentFunction < ActiveRecord::Migration
# PostgreSQL only
def up
execute 'CREATE EXTENSION IF NOT EXISTS unaccent;'
execute 'CREATE EXTENSION IF NOT EXISTS pg_trgm;'
execute "CREATE OR REPLACE FUNCTION f_unaccent(text)
RETURNS text AS
$func$
SELECT public.unaccent('public.unaccent', $1)
$func$ LANGUAGE sql IMMUTABLE;"
execute 'CREATE INDEX profiles_lower_unaccent_first_name_trgm_idx ON profiles
USING gin (lower(f_unaccent(first_name)) gin_trgm_ops);'
execute 'CREATE INDEX profiles_lower_unaccent_last_name_trgm_idx ON profiles
USING gin (lower(f_unaccent(last_name)) gin_trgm_ops);'
end
def down
execute 'DROP INDEX profiles_lower_unaccent_first_name_trgm_idx;'
execute 'DROP INDEX profiles_lower_unaccent_last_name_trgm_idx;'
execute 'DROP FUNCTION f_unaccent(text);'
execute 'DROP EXTENSION pg_trgm;'
execute 'DROP EXTENSION unaccent;'
end
end