From 98cbeae49c2144d6e1a4bc6114295e79a23e36c2 Mon Sep 17 00:00:00 2001 From: Michael Loftis Date: Tue, 22 Jan 2019 15:35:21 +0000 Subject: [PATCH] slightly changes definition so that autovacuum works paralell safe too --- ...90122153157_update_activity_visibility.exs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 priv/repo/migrations/20190122153157_update_activity_visibility.exs diff --git a/priv/repo/migrations/20190122153157_update_activity_visibility.exs b/priv/repo/migrations/20190122153157_update_activity_visibility.exs new file mode 100644 index 000000000..30075137c --- /dev/null +++ b/priv/repo/migrations/20190122153157_update_activity_visibility.exs @@ -0,0 +1,36 @@ +defmodule Pleroma.Repo.Migrations.UpdateActivityVisibility do + use Ecto.Migration + @disable_ddl_transaction true + + def up do + definition = """ + create or replace function activity_visibility(actor varchar, recipients varchar[], data jsonb) returns varchar as $$ + DECLARE + fa varchar; + public varchar := 'https://www.w3.org/ns/activitystreams#Public'; + BEGIN + SELECT COALESCE(users.follower_address, '') into fa from users where users.ap_id = actor; + + IF data->'to' ? public THEN + RETURN 'public'; + ELSIF data->'cc' ? public THEN + RETURN 'unlisted'; + ELSIF ARRAY[fa] && recipients THEN + RETURN 'private'; + ELSIF not(ARRAY[fa, public] && recipients) THEN + RETURN 'direct'; + ELSE + RETURN 'unknown'; + END IF; + END; + $$ LANGUAGE plpgsql IMMUTABLE PARALLEL SAFE SECURITY DEFINER; + """ + + execute(definition) + + end + + def down do + + end +end -- 2.45.2