Created
April 28, 2014 23:12
-
-
Save zetxek/11386701 to your computer and use it in GitHub Desktop.
Rails migration to create a Postgresql function that stripts every accent and outputs the string as lowercase, as seen in http://stackoverflow.com/questions/9243322/postgres-accent-insensitive-like-search-in-rails-3-1-on-heroku
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding : utf-8 -*- | |
class AddLowerUnaccentFunctionToDb < ActiveRecord::Migration | |
def self.up | |
execute "CREATE OR REPLACE FUNCTION lower_unaccent(character varying) | |
RETURNS text | |
AS $$ | |
SELECT lower(translate($1 | |
, '¹²³áàâãäåāăąÀÁÂÃÄÅĀĂĄÆćčç©ĆČÇĐÐèéêёëēĕėęěÈÊËЁĒĔĖĘĚ€ğĞıìíîïìĩīĭÌÍÎÏЇÌĨĪĬłŁńňñŃŇÑòóôõöōŏőøÒÓÔÕÖŌŎŐØŒř®ŘšşșߊŞȘùúûüũūŭůÙÚÛÜŨŪŬŮýÿÝŸžżźŽŻŹ' | |
, '123aaaaaaaaaaaaaaaaaaacccccccddeeeeeeeeeeeeeeeeeeeeggiiiiiiiiiiiiiiiiiillnnnnnnooooooooooooooooooorrrsssssssuuuuuuuuuuuuuuuuyyyyzzzzzz' | |
)); | |
$$ IMMUTABLE STRICT LANGUAGE SQL;" | |
end | |
def self.down | |
execute "drop function lower_unaccent(text) cascade" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment