Merge pull request 'Correct old migrations for expiring activities and user access tokens' (#7862) from fix-old-migrations into develop

Reviewed-on: https://git.pleroma.social/pleroma/pleroma/pulls/7862
This commit is contained in:
feld 2026-03-25 19:25:18 +00:00
commit dc7bd82968
3 changed files with 19 additions and 6 deletions

View file

@ -0,0 +1 @@
Correct old migrations for expiring activities and user access tokens.

View file

@ -23,10 +23,12 @@ defmodule Pleroma.Repo.Migrations.MoveActivityExpirationsToOban do
|> Pleroma.Repo.stream()
|> Stream.each(fn expiration ->
with {:ok, expires_at} <- DateTime.from_naive(expiration.scheduled_at, "Etc/UTC") do
Pleroma.Workers.PurgeExpiredActivity.enqueue(%{
activity_id: FlakeId.to_string(expiration.activity_id),
expires_at: expires_at
})
Pleroma.Workers.PurgeExpiredActivity.enqueue(
%{
activity_id: FlakeId.to_string(expiration.activity_id)
},
scheduled_at: expires_at
)
end
end)
|> Stream.run()

View file

@ -21,7 +21,7 @@ defmodule Pleroma.Repo.Migrations.MoveTokensExpirationIntoOban do
from(t in Pleroma.Web.OAuth.Token, where: t.valid_until > ^NaiveDateTime.utc_now())
|> Pleroma.Repo.stream()
|> Stream.each(fn token ->
Pleroma.Workers.PurgeExpiredToken.enqueue(%{
enqueue(%{
token_id: token.id,
valid_until: DateTime.from_naive!(token.valid_until, "Etc/UTC"),
mod: Pleroma.Web.OAuth.Token
@ -33,7 +33,7 @@ defmodule Pleroma.Repo.Migrations.MoveTokensExpirationIntoOban do
from(t in Pleroma.MFA.Token, where: t.valid_until > ^NaiveDateTime.utc_now())
|> Pleroma.Repo.stream()
|> Stream.each(fn token ->
Pleroma.Workers.PurgeExpiredToken.enqueue(%{
enqueue(%{
token_id: token.id,
valid_until: DateTime.from_naive!(token.valid_until, "Etc/UTC"),
mod: Pleroma.MFA.Token
@ -41,4 +41,14 @@ defmodule Pleroma.Repo.Migrations.MoveTokensExpirationIntoOban do
end)
|> Stream.run()
end
@spec enqueue(%{token_id: integer(), valid_until: DateTime.t()}) ::
{:ok, Oban.Job.t()} | {:error, Ecto.Changeset.t()}
defp enqueue(args) do
{scheduled_at, args} = Map.pop(args, :valid_until)
args
|> Pleroma.Workers.PurgeExpiredToken.new(scheduled_at: scheduled_at)
|> Oban.insert()
end
end