db: drop legacy key fields in users table
This commit is contained in:
parent
ea2de1f28a
commit
898b98e5dd
4 changed files with 32 additions and 3 deletions
|
@ -100,7 +100,6 @@ defmodule Pleroma.User do
|
||||||
field(:password_hash, :string)
|
field(:password_hash, :string)
|
||||||
field(:password, :string, virtual: true)
|
field(:password, :string, virtual: true)
|
||||||
field(:password_confirmation, :string, virtual: true)
|
field(:password_confirmation, :string, virtual: true)
|
||||||
field(:keys, :string)
|
|
||||||
field(:ap_id, :string)
|
field(:ap_id, :string)
|
||||||
field(:avatar, :map, default: %{})
|
field(:avatar, :map, default: %{})
|
||||||
field(:local, :boolean, default: true)
|
field(:local, :boolean, default: true)
|
||||||
|
|
|
@ -11,7 +11,7 @@ def up do
|
||||||
# Also this MUST use select, else the migration will fail in future installs with new user fields!
|
# Also this MUST use select, else the migration will fail in future installs with new user fields!
|
||||||
from(u in Pleroma.User,
|
from(u in Pleroma.User,
|
||||||
where: u.local == true,
|
where: u.local == true,
|
||||||
select: {u.id, u.keys, u.ap_id}
|
select: {u.id, fragment("?.keys", u), u.ap_id}
|
||||||
)
|
)
|
||||||
|> Repo.stream(timeout: :infinity)
|
|> Repo.stream(timeout: :infinity)
|
||||||
|> Enum.each(fn
|
|> Enum.each(fn
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
defmodule Pleroma.Repo.Migrations.UsersDropLegacyKeyFields do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def up() do
|
||||||
|
alter table(:users) do
|
||||||
|
remove :keys, :text
|
||||||
|
remove :public_key, :text
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def down() do
|
||||||
|
# Using raw query since the "keys" field may not exist in the Elixir Ecto schema
|
||||||
|
# causing issues when migrating data back and this requires column adds to be raw query too
|
||||||
|
"""
|
||||||
|
ALTER TABLE public.users
|
||||||
|
ADD COLUMN keys text,
|
||||||
|
ADD COLUMN public_key text;
|
||||||
|
"""
|
||||||
|
|> Pleroma.Repo.query!([], timeout: :infinity)
|
||||||
|
|
||||||
|
"""
|
||||||
|
UPDATE public.users AS u
|
||||||
|
SET keys = s.private_key
|
||||||
|
FROM public.signing_keys AS s
|
||||||
|
WHERE s.user_id = u.id AND
|
||||||
|
u.local AND
|
||||||
|
s.private_key IS NOT NULL;
|
||||||
|
"""
|
||||||
|
|> Pleroma.Repo.query!([], timeout: :infinity)
|
||||||
|
end
|
||||||
|
end
|
|
@ -1708,7 +1708,6 @@ test "delete/1 purges a user when they wouldn't be fully deleted" do
|
||||||
bio: "eyy lmao",
|
bio: "eyy lmao",
|
||||||
name: "qqqqqqq",
|
name: "qqqqqqq",
|
||||||
password_hash: "pdfk2$1b3n159001",
|
password_hash: "pdfk2$1b3n159001",
|
||||||
keys: "RSA begin buplic key",
|
|
||||||
avatar: %{"a" => "b"},
|
avatar: %{"a" => "b"},
|
||||||
tags: ["qqqqq"],
|
tags: ["qqqqq"],
|
||||||
banner: %{"a" => "b"},
|
banner: %{"a" => "b"},
|
||||||
|
|
Loading…
Reference in a new issue