2016-06-14 09:57:39 +02:00
|
|
|
class CreateUnaccentFunction < ActiveRecord::Migration
|
|
|
|
|
|
|
|
# PostgreSQL only
|
|
|
|
def up
|
2016-06-27 09:10:33 +02:00
|
|
|
execute 'CREATE EXTENSION IF NOT EXISTS unaccent;'
|
|
|
|
execute 'CREATE EXTENSION IF NOT EXISTS pg_trgm;'
|
2016-06-14 09:57:39 +02:00
|
|
|
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;'
|
2016-06-16 10:39:00 +02:00
|
|
|
execute 'DROP FUNCTION f_unaccent(text);'
|
|
|
|
execute 'DROP EXTENSION pg_trgm;'
|
|
|
|
execute 'DROP EXTENSION unaccent;'
|
2016-06-14 09:57:39 +02:00
|
|
|
end
|
|
|
|
end
|