Migrations: Add a fixup migration for the muted_notifications
authorlain <lain@soykaf.club>
Mon, 4 Nov 2019 14:38:28 +0000 (15:38 +0100)
committerlain <lain@soykaf.club>
Mon, 4 Nov 2019 14:38:28 +0000 (15:38 +0100)
This sets info->muted_notifications to an emtpy array if it is explicitly set
to null before. This can happen when safe_jsonb_set coalesces to a jsonb null,
which will make ecto not use the default value of [] anymore because it has been
explicitly overwritten.

priv/repo/migrations/20191104143558_fix_null_muted_notification_fields.exs [new file with mode: 0644]

diff --git a/priv/repo/migrations/20191104143558_fix_null_muted_notification_fields.exs b/priv/repo/migrations/20191104143558_fix_null_muted_notification_fields.exs
new file mode 100644 (file)
index 0000000..e17e759
--- /dev/null
@@ -0,0 +1,7 @@
+defmodule Pleroma.Repo.Migrations.FixNullMutedNotificationFields do
+  use Ecto.Migration
+
+  def change do
+    execute("update users set info = safe_jsonb_set(info, '{muted_notifications}', '[]'::jsonb, true) where local = true and info->'muted_notifications' = 'null'::jsonb")
+  end
+end