dwyl/alog

Updating Users using the Alog approach

Opened this issue ยท 4 comments

I am currently in the process of trying to update all the users in my database to add new columns to the table.

I tried using the Alog update function which inserts a new row with the updated information but this is giving me an error because it is changing my email_hash and password values. (Also using dwyl fields)

This is an issue because it means that if I update the user that user can no longer log into the application.

If I change the Alog update function to Repo.update(User, params) it works fine but we have no record of the change.

@nelsonic do you have any thoughts on this?

User.all()
  |> Enum.map(fn(user) ->
  params =
    case user.admin do
      true ->
        %{
          role: "site_admin",
          verified: user.inserted_at
        }

      _ ->
        %{role: "venue_admin"}
    end

  user
  |> Ecto.Changeset.cast(params, [
  :email, :password, :admin, :role, :verified, :password_reset_token,
  :password_reset_token_sent_at
  ])
|> User.update()

This is the type of function that I have written

@RobStallion why is adding a couple of new fields changing the email_hash and password values?

@nelsonic It's not the addition of the new fields that is changing the email_hash and password. It's the User.update (Alog.update) function which appears to be changing the values.

@RobStallion That shouldn't happen ... ๐Ÿ˜•
If you have time to screen-share (remote pair) on this, please let me know.