saving following_address for existing users
authorAlex S <alex.strizhakov@gmail.com>
Wed, 10 Jul 2019 13:02:22 +0000 (16:02 +0300)
committerAlex S <alex.strizhakov@gmail.com>
Wed, 10 Jul 2019 14:42:18 +0000 (17:42 +0300)
priv/repo/migrations/20190710125158_add_following_address_from_source_data.exs [new file with mode: 0644]

diff --git a/priv/repo/migrations/20190710125158_add_following_address_from_source_data.exs b/priv/repo/migrations/20190710125158_add_following_address_from_source_data.exs
new file mode 100644 (file)
index 0000000..779aa38
--- /dev/null
@@ -0,0 +1,20 @@
+defmodule Pleroma.Repo.Migrations.AddFollowingAddressFromSourceData do
+  use Ecto.Migration
+  import Ecto.Query
+  alias Pleroma.User
+
+  def change do
+    query =
+      User.external_users_query()
+      |> select([u], struct(u, [:id, :ap_id, :info]))
+
+    Pleroma.Repo.stream(query)
+    |> Enum.each(fn
+      %{info: %{source_data: source_data}} = user ->
+        Ecto.Changeset.cast(user, %{following_address: source_data["following"]}, [
+          :following_address
+        ])
+        |> Pleroma.Repo.update()
+    end)
+  end
+end