1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Repo.Migrations.UpdateMarkers do
18 defp update_markers do
19 now = NaiveDateTime.utc_now()
22 from(q in "notifications",
24 timeline: "notifications",
27 type(fragment("MAX( CASE WHEN seen = true THEN id ELSE null END )"), :string)
32 |> Enum.map(fn %{last_read_id: last_read_id} = attrs ->
34 |> Map.put(:last_read_id, last_read_id || "")
35 |> Map.put_new(:inserted_at, now)
36 |> Map.put_new(:updated_at, now)
40 |> Enum.chunk_every(1000)
41 |> Enum.each(fn markers_attrs_chunked ->
42 Repo.insert_all("markers", markers_attrs_chunked,
43 on_conflict: {:replace, [:last_read_id]},
44 conflict_target: [:user_id, :timeline]