ash_hq/priv/repo/migrations/20220328162643_add_tsvector_indices.exs
Zach Daniel de97413240 WIP
2022-03-29 12:12:28 -04:00

25 lines
605 B
Elixir

defmodule AshHq.Repo.Migrations.AddTsvectorIndices do
use Ecto.Migration
@config %{
guides: {:name, :text},
library_versions: {:version, :doc},
options: {:name, :doc},
dsls: {:name, :doc},
extensions: {:name, :doc}
}
def change do
for {table, {header, text}} <- @config do
execute """
CREATE INDEX #{table}_search_index ON #{table} USING GIN((
setweight(to_tsvector('english', #{header}), 'A') ||
setweight(to_tsvector('english', #{text}), 'D')
));
""",
"""
DROP INDEX #{table}_search_index
"""
end
end
end