Last active
September 15, 2017 13:53
-
-
Save fertapric/5a6a3d32ead9f72e97d4c4bdbf17d5c4 to your computer and use it in GitHub Desktop.
Shortcut for creating a trgm index (`pg_tgrm`).
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
defmodule Core.Repo.Migration do | |
@moduledoc """ | |
Migrations are used to modify your database schema over time. | |
This module provides many helpers for migrating the database, along with the ones provided | |
by `Ecto.Migration`. | |
""" | |
defmacro __using__(_) do | |
quote do | |
use Ecto.Migration | |
import unquote(__MODULE__) | |
end | |
end | |
@doc """ | |
Shortcut for creating a trgm index (`pg_tgrm`). | |
See `Ecto.Migration.index/3` for more information. | |
""" | |
@spec trgm_index(atom, atom, Keyword.t) :: map | |
def trgm_index(table, column, opts \\ []) do | |
opts = Keyword.merge([using: "GIN", name: "#{table}_#{column}_trgm_index"], opts) | |
Ecto.Migration.index(table, ["#{column} gin_trgm_ops"], opts) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment