Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into remake-remodel
[akkoma] / priv / repo / migrations / 20190711042021_create_safe_jsonb_set.exs
1 defmodule Pleroma.Repo.Migrations.CreateSafeJsonbSet do
2 use Ecto.Migration
3 alias Pleroma.User
4
5 def change do
6 execute("""
7 create or replace function safe_jsonb_set(target jsonb, path text[], new_value jsonb, create_missing boolean default true) returns jsonb as $$
8 declare
9 result jsonb;
10 begin
11 result := jsonb_set(target, path, coalesce(new_value, 'null'::jsonb), create_missing);
12 if result is NULL then
13 raise 'jsonb_set tried to wipe the object, please report this incindent to Pleroma bug tracker. https://git.pleroma.social/pleroma/pleroma/issues/new';
14 return target;
15 else
16 return result;
17 end if;
18 end;
19 $$ language plpgsql;
20 """)
21 end
22 end