1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Repo.Migrations.AddFtsIndexToObjectsTwo do
9 execute("create extension if not exists rum")
12 index(:objects, ["(to_tsvector('english', data->>'content'))"],
18 alter table(:objects) do
19 add(:fts_content, :tsvector)
22 execute("CREATE FUNCTION objects_fts_update() RETURNS trigger AS $$
24 new.fts_content := to_tsvector(new.data->>'content');
30 "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');"
33 execute("CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON objects
34 FOR EACH ROW EXECUTE PROCEDURE objects_fts_update()")
36 execute("UPDATE objects SET updated_at = NOW()")
40 execute("drop index if exists objects_fts")
41 execute("drop trigger if exists tsvectorupdate on objects")
42 execute("drop function if exists objects_fts_update()")
44 alter table(:objects) do
45 remove(:fts_content, :tsvector)
49 index(:objects, ["(to_tsvector('english', data->>'content'))"],