diff --git a/dbschema/common.gel b/dbschema/common.gel index 21165b2531..a17231c4cc 100644 --- a/dbschema/common.gel +++ b/dbschema/common.gel @@ -1,3 +1,5 @@ +using extension pg_unaccent; + module default { global currentActorId: uuid; global currentActor := (select Actor filter .id = global currentActorId); @@ -5,17 +7,13 @@ module default { global currentRoles := (global currentActor).roles; scalar type ReportPeriod extending enum; - - # Helper function to workaround native support for sort ignoring accents - # https://stackoverflow.com/a/11007216 - # https://github.com/geldata/gel/issues/386 - function str_sortable(value: str) -> str - using ( + + # Helper function to sort strings in a more natural way + function str_sortable(value: str) -> str using ( str_lower( - re_replace('Ñ', 'N', + ext::pg_unaccent::unaccent( str_trim(re_replace('[ [\\]|,\\-$]+', ' ', value, flags := 'g')), - flags := 'g' - ) + ) ) ); diff --git a/dbschema/migrations/00022-m1p34dr.edgeql b/dbschema/migrations/00022-m1p34dr.edgeql new file mode 100644 index 0000000000..a1800ef70f --- /dev/null +++ b/dbschema/migrations/00022-m1p34dr.edgeql @@ -0,0 +1,8 @@ +CREATE MIGRATION m1xp5mbrgbcsdkvhimirvlj2hueu7m7aeyowjcp3wl4itrzityln4q + ONTO m12v6mjpnma3kdngompvtea3ldgqtcpm45b2wcjxwvt5jxyu53zsuq +{ + CREATE EXTENSION pg_unaccent VERSION '1.1'; + ALTER FUNCTION default::str_sortable(value: std::str) USING ( + std::str_lower(ext::pg_unaccent::unaccent(std::str_trim(std::re_replace(r'[ [\]|,\-$]+', ' ', value, flags := 'g')))) + ); +};