Fix migration for empty db.
[akkoma] / priv / repo / migrations / 20171109114020_fill_actor_field.exs
1 defmodule Pleroma.Repo.Migrations.FillActorField do
2 use Ecto.Migration
3
4 alias Pleroma.{Repo, Activity}
5
6 def up do
7 max = Repo.aggregate(Activity, :max, :id)
8 if max do
9 IO.puts("#{max} activities")
10 chunks = 0..(round(max / 10_000))
11
12 Enum.each(chunks, fn (i) ->
13 min = i * 10_000
14 max = min + 10_000
15 execute("""
16 update activities set actor = data->>'actor' where id > #{min} and id <= #{max};
17 """)
18 |> IO.inspect
19 end)
20 end
21 end
22
23 def down do
24 end
25 end
26