2022-09-05 01:51:35 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Repo.Migrations.GenerateUnsetUserKeys do
|
|
|
|
use Ecto.Migration
|
|
|
|
import Ecto.Query
|
|
|
|
alias Pleroma.Keys
|
|
|
|
alias Pleroma.Repo
|
|
|
|
alias Pleroma.User
|
|
|
|
|
|
|
|
def change do
|
|
|
|
query =
|
|
|
|
from(u in User,
|
|
|
|
where: u.local == true,
|
|
|
|
where: is_nil(u.keys),
|
2022-11-28 13:34:54 +00:00
|
|
|
select: u.id
|
2022-09-05 01:51:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
Repo.stream(query)
|
|
|
|
|> Enum.each(fn user ->
|
|
|
|
with {:ok, pem} <- Keys.generate_rsa_pem() do
|
2022-11-28 13:34:54 +00:00
|
|
|
Ecto.Changeset.cast(%User{id: user}, %{keys: pem}, [:keys])
|
|
|
|
|> Repo.update(returning: false)
|
2022-09-05 01:51:35 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|