From: lain <lain@soykaf.club>
Date: Fri, 1 Nov 2019 12:31:55 +0000 (+0100)
Subject: Migrations: Add migration to fill empty info fields and make them non-null.
X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=8ad75f9ecf16641699248ac83acc9f4d0edeba88;p=akkoma

Migrations: Add migration to fill empty info fields and make them non-null.
---

diff --git a/priv/repo/migrations/20190711042020_fix_and_secure_user_info_field.exs b/priv/repo/migrations/20190711042020_fix_and_secure_user_info_field.exs
new file mode 100644
index 000000000..9602a8c41
--- /dev/null
+++ b/priv/repo/migrations/20190711042020_fix_and_secure_user_info_field.exs
@@ -0,0 +1,17 @@
+defmodule Pleroma.Repo.Migrations.FixAndSecureUserInfoField do
+  use Ecto.Migration
+
+  def up do
+    execute("UPDATE users SET info = '{}'::jsonb WHERE info IS NULL")
+
+    execute("ALTER TABLE users
+    ALTER COLUMN info SET NOT NULL
+    ")
+  end
+
+  def down do
+    execute("ALTER TABLE users
+    ALTER COLUMN info DROP NOT NULL
+    ")
+  end
+end