diff options
Diffstat (limited to 'priv/repo')
| -rw-r--r-- | priv/repo/migrations/20190115085500_create_user_fts_index.exs | 17 | ||||
| -rw-r--r-- | priv/repo/migrations/20190118074940_fix_user_trigram_index.exs | 22 | 
2 files changed, 39 insertions, 0 deletions
| diff --git a/priv/repo/migrations/20190115085500_create_user_fts_index.exs b/priv/repo/migrations/20190115085500_create_user_fts_index.exs new file mode 100644 index 000000000..499d67113 --- /dev/null +++ b/priv/repo/migrations/20190115085500_create_user_fts_index.exs @@ -0,0 +1,17 @@ +defmodule Pleroma.Repo.Migrations.CreateUserFtsIndex do +  use Ecto.Migration + +  def change do +    create index( +             :users, +             [ +               """ +               (setweight(to_tsvector('simple', regexp_replace(nickname, '\\W', ' ', 'g')), 'A') || +               setweight(to_tsvector('simple', regexp_replace(coalesce(name, ''), '\\W', ' ', 'g')), 'B')) +               """ +             ], +             name: :users_fts_index, +             using: :gin +           ) +  end +end diff --git a/priv/repo/migrations/20190118074940_fix_user_trigram_index.exs b/priv/repo/migrations/20190118074940_fix_user_trigram_index.exs new file mode 100644 index 000000000..b4e8c984c --- /dev/null +++ b/priv/repo/migrations/20190118074940_fix_user_trigram_index.exs @@ -0,0 +1,22 @@ +defmodule Pleroma.Repo.Migrations.FixUserTrigramIndex do +  use Ecto.Migration + +  def up do +    drop_if_exists(index(:users, [], name: :users_trigram_index)) + +    create( +      index(:users, ["(trim(nickname || ' ' || coalesce(name, ''))) gist_trgm_ops"], +        name: :users_trigram_index, +        using: :gist +      ) +    ) +  end + +  def down do +    drop_if_exists(index(:users, [], name: :users_trigram_index)) + +    create( +      index(:users, ["(nickname || name) gist_trgm_ops"], name: :users_trigram_index, using: :gist) +    ) +  end +end | 
