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},
|
|
|
|
extensions: {: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((
|
|
|
|
setweight(to_tsvector('simple', #{header}), 'A') ||
|
|
|
|
setweight(to_tsvector('simple', #{text}), 'D')
|
|
|
|
));
|
|
|
|
""",
|
|
|
|
"""
|
|
|
|
DROP INDEX #{table}_search_index
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|