I have function in changeset pipeline to encrypt token.
def changeset(user, params \\ %{}) do
user
|> cast(params, [:id, :token]
|> encrypt(:token)
end
Since this function is new, the old data is still not encrypted and I need to do it manually. Then I met the problem.
If I pass the original token to changeset, it will treat the value as if no changes. The encrypt in pipeline is not working and value not update.
If I encrypted the token and pass to changeset, it marked as changes, and encrypt function applied. However, it encrypted twice.
One clumsy way is to add a checking on encrypt to check if the token is encrypted or not. But remember before we passed new token to changeset, we still need to check if the token is encrypted. Which means, we do the checking twice.
So I'm looking for a simple solution if someone have the idea.
Cheers