1 defmodule Pleroma.Repo.Migrations.UpdateMarkers do
14 defp update_markers do
15 now = NaiveDateTime.utc_now()
18 from(q in "notifications",
20 timeline: "notifications",
23 type(fragment("MAX( CASE WHEN seen = true THEN id ELSE null END )"), :string)
28 |> Enum.map(fn %{last_read_id: last_read_id} = attrs ->
30 |> Map.put(:last_read_id, last_read_id || "")
31 |> Map.put_new(:inserted_at, now)
32 |> Map.put_new(:updated_at, now)
35 Repo.insert_all("markers", markers_attrs,
36 on_conflict: {:replace, [:last_read_id]},
37 conflict_target: [:user_id, :timeline]