From: href Date: Thu, 24 Jan 2019 13:13:20 +0000 (+0100) Subject: Fix postgres activity_visibility when running in autovacuum X-Git-Url: http://git.squeep.com/?a=commitdiff_plain;h=e02b19d1d76e713e646ddcdd2002d4e05b10b2f8;p=akkoma Fix postgres activity_visibility when running in autovacuum --- diff --git a/priv/repo/migrations/20190124131141_update_activity_visibility_again.exs b/priv/repo/migrations/20190124131141_update_activity_visibility_again.exs new file mode 100644 index 000000000..0519a5143 --- /dev/null +++ b/priv/repo/migrations/20190124131141_update_activity_visibility_again.exs @@ -0,0 +1,37 @@ +defmodule Pleroma.Repo.Migrations.UpdateActivityVisibilityAgain 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 public.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