1 defmodule Pleroma.Repo.Migrations.AddFtsIndexToObjectsTwo do
5 execute("create extension if not exists rum")
8 index(:objects, ["(to_tsvector('english', data->>'content'))"],
14 alter table(:objects) do
15 add(:fts_content, :tsvector)
18 execute("CREATE FUNCTION objects_fts_update() RETURNS trigger AS $$
20 new.fts_content := to_tsvector('english', new.data->>'content');
26 "create index if not exists objects_fts on objects using RUM (fts_content rum_tsvector_addon_ops, inserted_at) with (attach = 'inserted_at', to = 'fts_content');"
29 execute("CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON objects
30 FOR EACH ROW EXECUTE PROCEDURE objects_fts_update()")
32 execute("UPDATE objects SET updated_at = NOW()")
36 execute("drop index if exists objects_fts")
37 execute("drop trigger if exists tsvectorupdate on objects")
38 execute("drop function if exists objects_fts_update()")
40 alter table(:objects) do
41 remove(:fts_content, :tsvector)
45 index(:objects, ["(to_tsvector('english', data->>'content'))"],