Migrations: Add migration to fill empty info fields and make them non-null.
authorlain <lain@soykaf.club>
Fri, 1 Nov 2019 12:31:55 +0000 (13:31 +0100)
committerlain <lain@soykaf.club>
Fri, 1 Nov 2019 12:31:55 +0000 (13:31 +0100)
priv/repo/migrations/20190711042020_fix_and_secure_user_info_field.exs [new file with mode: 0644]

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 (file)
index 0000000..9602a8c
--- /dev/null
@@ -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