2022-09-05 01:51:35 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2022-09-05 01:51:35 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-11-13 13:15:19 +00:00
|
|
|
defmodule User do
|
|
|
|
use Ecto.Schema
|
|
|
|
|
|
|
|
schema "users" do
|
|
|
|
field(:keys, :string)
|
|
|
|
field(:local, :boolean, default: true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-09-05 01:51:35 +00:00
|
|
|
defmodule Pleroma.Repo.Migrations.GenerateUnsetUserKeys do
|
|
|
|
use Ecto.Migration
|
|
|
|
import Ecto.Query
|
|
|
|
alias Pleroma.Keys
|
|
|
|
alias Pleroma.Repo
|
|
|
|
|
|
|
|
def change do
|
|
|
|
query =
|
|
|
|
from(u in User,
|
|
|
|
where: u.local == true,
|
|
|
|
where: is_nil(u.keys),
|
|
|
|
select: u
|
|
|
|
)
|
|
|
|
|
|
|
|
Repo.stream(query)
|
|
|
|
|> Enum.each(fn user ->
|
|
|
|
with {:ok, pem} <- Keys.generate_rsa_pem() do
|
|
|
|
Ecto.Changeset.cast(user, %{keys: pem}, [:keys])
|
|
|
|
|> Repo.update()
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|