dwyl / alog

🌲 alog (Append-only Log) is an easy way to start using the Lambda/Kappa architecture in your Elixir/Phoenix Apps while still using PostgreSQL (with Ecto).
GNU General Public License v2.0
15 stars 2 forks source link

Updating Users using the Alog approach #56

Open RobStallion opened 5 years ago

RobStallion commented 5 years ago

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?

RobStallion commented 5 years ago
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

nelsonic commented 5 years ago

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

RobStallion commented 5 years ago

@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.

nelsonic commented 5 years ago

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