ash_hq/priv/repo/migrations/20220330010101_add_tsvector_indices.exs

28 lines
663 B
Elixir
Raw Normal View History

2022-03-29 08:47:43 +13:00
defmodule AshHq.Repo.Migrations.AddTsvectorIndices do
use Ecto.Migration
@config %{
guides: {:name, :text},
library_versions: {:version, :doc},
options: {:name, :doc},
2022-03-29 11:05:19 +13:00
dsls: {:name, :doc},
2022-03-30 17:40:17 +13:00
extensions: {:name, :doc},
functions: {:name, :doc},
modules: {:name, :doc}
2022-03-29 08:47:43 +13:00
}
def change do
for {table, {header, text}} <- @config do
execute """
CREATE INDEX #{table}_search_index ON #{table} USING GIN((
2022-03-30 05:12:28 +13:00
setweight(to_tsvector('english', #{header}), 'A') ||
setweight(to_tsvector('english', #{text}), 'D')
2022-03-29 08:47:43 +13:00
));
""",
"""
DROP INDEX #{table}_search_index
"""
end
end
end