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:
commit
dc7bd82968
3 changed files with 19 additions and 6 deletions
1
changelog.d/old-migrations.fix
Normal file
1
changelog.d/old-migrations.fix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Correct old migrations for expiring activities and user access tokens.
|
||||||
|
|
@ -23,10 +23,12 @@ defmodule Pleroma.Repo.Migrations.MoveActivityExpirationsToOban do
|
||||||
|> Pleroma.Repo.stream()
|
|> Pleroma.Repo.stream()
|
||||||
|> Stream.each(fn expiration ->
|
|> Stream.each(fn expiration ->
|
||||||
with {:ok, expires_at} <- DateTime.from_naive(expiration.scheduled_at, "Etc/UTC") do
|
with {:ok, expires_at} <- DateTime.from_naive(expiration.scheduled_at, "Etc/UTC") do
|
||||||
Pleroma.Workers.PurgeExpiredActivity.enqueue(%{
|
Pleroma.Workers.PurgeExpiredActivity.enqueue(
|
||||||
activity_id: FlakeId.to_string(expiration.activity_id),
|
%{
|
||||||
expires_at: expires_at
|
activity_id: FlakeId.to_string(expiration.activity_id)
|
||||||
})
|
},
|
||||||
|
scheduled_at: expires_at
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|> Stream.run()
|
|> Stream.run()
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ defmodule Pleroma.Repo.Migrations.MoveTokensExpirationIntoOban do
|
||||||
from(t in Pleroma.Web.OAuth.Token, where: t.valid_until > ^NaiveDateTime.utc_now())
|
from(t in Pleroma.Web.OAuth.Token, where: t.valid_until > ^NaiveDateTime.utc_now())
|
||||||
|> Pleroma.Repo.stream()
|
|> Pleroma.Repo.stream()
|
||||||
|> Stream.each(fn token ->
|
|> Stream.each(fn token ->
|
||||||
Pleroma.Workers.PurgeExpiredToken.enqueue(%{
|
enqueue(%{
|
||||||
token_id: token.id,
|
token_id: token.id,
|
||||||
valid_until: DateTime.from_naive!(token.valid_until, "Etc/UTC"),
|
valid_until: DateTime.from_naive!(token.valid_until, "Etc/UTC"),
|
||||||
mod: Pleroma.Web.OAuth.Token
|
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())
|
from(t in Pleroma.MFA.Token, where: t.valid_until > ^NaiveDateTime.utc_now())
|
||||||
|> Pleroma.Repo.stream()
|
|> Pleroma.Repo.stream()
|
||||||
|> Stream.each(fn token ->
|
|> Stream.each(fn token ->
|
||||||
Pleroma.Workers.PurgeExpiredToken.enqueue(%{
|
enqueue(%{
|
||||||
token_id: token.id,
|
token_id: token.id,
|
||||||
valid_until: DateTime.from_naive!(token.valid_until, "Etc/UTC"),
|
valid_until: DateTime.from_naive!(token.valid_until, "Etc/UTC"),
|
||||||
mod: Pleroma.MFA.Token
|
mod: Pleroma.MFA.Token
|
||||||
|
|
@ -41,4 +41,14 @@ defmodule Pleroma.Repo.Migrations.MoveTokensExpirationIntoOban do
|
||||||
end)
|
end)
|
||||||
|> Stream.run()
|
|> Stream.run()
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue