Skip to content

Commit 8e4cf29

Browse files
committed
Fix migration for adding done to task lists
1 parent 0e6eb76 commit 8e4cf29

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

priv/repo/migrations/20171106045740_add_done_to_task_list.exs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ defmodule CodeCorps.Repo.Migrations.AddDoneToTaskList do
1818
task_list_query =
1919
from(tl in "task_lists", where: [done: true], select: [:id])
2020

21-
# tests do not have any data, so we need to account for potential nil
22-
case task_list_query |> Repo.one do
23-
%{id: done_list_id} ->
24-
task_update_query = from t in "tasks",
25-
where: [status: "closed"],
26-
update: [set: [task_list_id: ^done_list_id]]
27-
task_update_query |> Repo.update_all([])
28-
nil -> nil
29-
end
21+
task_list_query |> Repo.all() |> Enum.each(fn task ->
22+
# tests do not have any data, so we need to account for potential nil
23+
case task do
24+
%{id: done_list_id} ->
25+
task_update_query = from t in "tasks",
26+
where: [status: "closed"],
27+
update: [set: [task_list_id: ^done_list_id]]
28+
task_update_query |> Repo.update_all([])
29+
nil -> nil
30+
end
31+
end)
3032
end
3133

3234
def down do

0 commit comments

Comments
 (0)