mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-25 15:39:19 +00:00
1a4238bf98
Since those old migrations will now most likely only run during db init, there’s not much point in running them in the background concurrently anyway, so just drop the cncurrent setting rather than disabling migration locks.
49 lines
1.3 KiB
Elixir
49 lines
1.3 KiB
Elixir
defmodule Pleroma.Repo.Migrations.AddVisibilityFunction do
|
|
use Ecto.Migration
|
|
|
|
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;
|
|
"""
|
|
|
|
execute(definition)
|
|
|
|
create(
|
|
index(:activities, ["activity_visibility(actor, recipients, data)"],
|
|
name: :activities_visibility_index
|
|
)
|
|
)
|
|
end
|
|
|
|
def down do
|
|
drop_if_exists(
|
|
index(:activities, ["activity_visibility(actor, recipients, data)"],
|
|
name: :activities_visibility_index
|
|
)
|
|
)
|
|
|
|
execute(
|
|
"drop function if exists activity_visibility(actor varchar, recipients varchar[], data jsonb)"
|
|
)
|
|
end
|
|
end
|