Skip to content

Commit 435ee74

Browse files
authored
Merge pull request #2104 from hexlet-codebattle/populate-update-pass
make populate users helper update passwords
2 parents b31f069 + 942c180 commit 435ee74

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

services/app/apps/codebattle/lib/codebattle/utils/populate_users.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ defmodule Codebattle.Utils.PopulateUsers do
77
file
88
|> File.stream!()
99
|> NimbleCSV.RFC4180.parse_stream()
10-
|> Stream.chunk_every(500)
10+
|> Stream.chunk_every(100)
1111
|> Enum.each(&process_batch(&1, utc_now))
1212
end
1313

1414
defp process_batch(users, now) do
1515
users = Enum.map(users, &row_to_user(&1, now))
16-
Codebattle.Repo.insert_all(Codebattle.User, users)
16+
17+
Codebattle.Repo.insert_all(Codebattle.User, users,
18+
on_conflict: {:replace, [:password_hash]},
19+
conflict_target: [:name]
20+
)
1721
end
1822

1923
defp row_to_user([name, password], now) do

0 commit comments

Comments
 (0)