fix migrate
This commit is contained in:
parent
9a4afbd2a0
commit
aa64b3108b
@ -56,8 +56,9 @@ defmodule Pleroma.Marker do
|
||||
where: q.user_id == ^user.id,
|
||||
select: %{
|
||||
timeline: "notifications",
|
||||
user_id: ^user.id,
|
||||
unread_count: fragment("SUM( CASE WHEN seen = false THEN 1 ELSE 0 END ) as unread_count")
|
||||
user_id: type(^user.id, :string),
|
||||
unread_count: fragment("SUM( CASE WHEN seen = false THEN 1 ELSE 0 END )"),
|
||||
last_read_id: type(fragment("MAX( CASE WHEN seen = true THEN id ELSE null END )"), :string)
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -25,25 +25,21 @@ defmodule Pleroma.Repo.Migrations.AddUnreadToMarker do
|
||||
select: %{
|
||||
timeline: "notifications",
|
||||
user_id: q.user_id,
|
||||
unread_count: fragment("COUNT(*) FILTER (WHERE seen = false) as unread_count"),
|
||||
last_read_id: fragment("(MAX(id) FILTER (WHERE seen = true)::text) as last_read_id ")
|
||||
unread_count: fragment("SUM( CASE WHEN seen = false THEN 1 ELSE 0 END )"),
|
||||
last_read_id: type(fragment("MAX( CASE WHEN seen = true THEN id ELSE null END )"), :string)
|
||||
},
|
||||
group_by: [q.user_id]
|
||||
)
|
||||
|> Repo.all()
|
||||
|> Enum.reduce(Ecto.Multi.new(), fn attrs, multi ->
|
||||
marker =
|
||||
|> Enum.each(fn attrs ->
|
||||
Pleroma.Marker
|
||||
|> struct(attrs)
|
||||
|> Ecto.Changeset.change()
|
||||
|
||||
multi
|
||||
|> Ecto.Multi.insert(attrs[:user_id], marker,
|
||||
|> Pleroma.Repo.insert(
|
||||
returning: true,
|
||||
on_conflict: {:replace, [:last_read_id, :unread_count]},
|
||||
conflict_target: [:user_id, :timeline]
|
||||
)
|
||||
end)
|
||||
|> Pleroma.Repo.transaction()
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user