Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.3KB

  1. defmodule Pleroma.Repo.Migrations.AddFtsIndexToObjectsTwo do
  2. use Ecto.Migration
  3. def up do
  4. execute("create extension if not exists rum")
  5. drop_if_exists(
  6. index(:objects, ["(to_tsvector('english', data->>'content'))"],
  7. using: :gin,
  8. name: :objects_fts
  9. )
  10. )
  11. alter table(:objects) do
  12. add(:fts_content, :tsvector)
  13. end
  14. execute("CREATE FUNCTION objects_fts_update() RETURNS trigger AS $$
  15. begin
  16. new.fts_content := to_tsvector(new.data->>'content');
  17. return new;
  18. end
  19. $$ LANGUAGE plpgsql")
  20. execute(
  21. "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');"
  22. )
  23. execute("CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON objects
  24. FOR EACH ROW EXECUTE PROCEDURE objects_fts_update()")
  25. execute("UPDATE objects SET updated_at = NOW()")
  26. end
  27. def down do
  28. execute("drop index if exists objects_fts")
  29. execute("drop trigger if exists tsvectorupdate on objects")
  30. execute("drop function if exists objects_fts_update()")
  31. alter table(:objects) do
  32. remove(:fts_content, :tsvector)
  33. end
  34. create_if_not_exists(
  35. index(:objects, ["(to_tsvector('english', data->>'content'))"],
  36. using: :gin,
  37. name: :objects_fts
  38. )
  39. )
  40. end
  41. end