From c0b37e5cf126aac046aed32de8e5883ea2f909ca Mon Sep 17 00:00:00 2001 From: Rui Lopes Date: Fri, 22 Dec 2023 19:18:56 +0000 Subject: [PATCH] refactor: remove repeated task --- lib/mix/tasks/anonimize.users.ex | 46 -------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 lib/mix/tasks/anonimize.users.ex diff --git a/lib/mix/tasks/anonimize.users.ex b/lib/mix/tasks/anonimize.users.ex deleted file mode 100644 index d145e1cb..00000000 --- a/lib/mix/tasks/anonimize.users.ex +++ /dev/null @@ -1,46 +0,0 @@ -defmodule Mix.Tasks.Anonimize.Users do - @moduledoc """ - Task to anonimize users - """ - use Mix.Task - import Ecto.Query, warn: false - - alias Safira.Accounts.{Attendee, User} - alias Safira.Repo - - def run(_args) do - Mix.Task.run("app.start") - users = Enum.shuffle(Repo.all(User)) - n = length(users) - - for i <- 0..(n - 1) do - anonimze_user(Enum.at(users, i), i + 1) - end - end - - defp anonimze_user(%User{} = user, index) do - attendee = - Attendee - |> where([a], a.user_id == ^user.id) - |> Repo.one() - - if not is_nil(attendee) do - attendee - |> Attendee.changeset(%{ - name: "Attendee #{index}", - nickname: "attendee#{index}", - avatar: nil, - cv: nil - }) - |> Repo.update!() - end - - user - |> User.changeset(%{ - email: "user#{index}@seium.org", - password: "password1234", - password_confirmation: "password1234" - }) - |> Repo.update!() - end -end