2022-02-25 22:11:42 -08:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-01 03:11:47 -08:00
|
|
|
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
|
2022-02-25 22:11:42 -08:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-09-14 04:08:12 -07:00
|
|
|
defmodule Pleroma.Repo.Migrations.DeleteNotificationWithoutActivity do
|
|
|
|
use Ecto.Migration
|
|
|
|
|
|
|
|
import Ecto.Query
|
|
|
|
alias Pleroma.Repo
|
|
|
|
|
|
|
|
def up do
|
|
|
|
from(
|
|
|
|
q in Pleroma.Notification,
|
|
|
|
left_join: c in assoc(q, :activity),
|
|
|
|
select: %{id: type(q.id, :integer)},
|
|
|
|
where: is_nil(c.id)
|
|
|
|
)
|
2020-09-15 20:18:50 -07:00
|
|
|
|> Repo.chunk_stream(1_000, :batches)
|
2020-09-14 04:08:12 -07:00
|
|
|
|> Stream.each(fn records ->
|
|
|
|
notification_ids = Enum.map(records, fn %{id: id} -> id end)
|
|
|
|
|
|
|
|
Repo.delete_all(
|
|
|
|
from(n in "notifications",
|
|
|
|
where: n.id in ^notification_ids
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end)
|
|
|
|
|> Stream.run()
|
|
|
|
end
|
|
|
|
|
|
|
|
def down do
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
end
|