Allow reusing deleted user emails

This commit is contained in:
alxlion
2026-08-07 05:59:31 +00:00
parent 40a98be34a
commit 6321b9e262
4 changed files with 27 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ defmodule Claper.Accounts.User do
use Ecto.Schema
import Ecto.Changeset
import Ecto.Query
@derive {
Flop.Schema,
@@ -129,7 +130,9 @@ defmodule Claper.Accounts.User do
|> validate_required([:email])
|> validate_format(:email, ~r/^[^\s]+@[^\s]+$/, message: "must have the @ sign and no spaces")
|> validate_length(:email, max: 160)
|> unsafe_validate_unique(:email, Claper.Repo)
|> unsafe_validate_unique(:email, Claper.Repo,
query: from(user in __MODULE__, where: is_nil(user.deleted_at))
)
|> unique_constraint(:email)
end