Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

52 lignes
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