Add pull_requests && done to task_list#1157
Conversation
| def create_changeset(struct, params) do | ||
| struct | ||
| |> cast(params, [:inbox]) | ||
| |> cast(params, [:inbox, :done, :pull_requests]) |
| Task | ||
| |> CodeCorps.Helpers.Query.project_filter(%{project_id: project.id}) | ||
| |> Repo.all() | ||
| |> Enum.each(&assign_task_to_done(&1, Enum.at(project.task_lists, 3))) |
There was a problem hiding this comment.
Calls assign_task_to_done(&1, 3rd_task_list_in_project), which is, I assume, the task list with done: true. It would, however, be preferable to call update_tasks_to_done/1 with that task list as an argument.
| done: true, | ||
| name: "Done", | ||
| position: 4 | ||
| } |
There was a problem hiding this comment.
I would probably remove inbox: false from the others here for consistency.
| TaskList.create_changeset(task_list, %{done: true}) | ||
| |> Repo.update() | ||
| end | ||
| defp update_done_column(task_list), do: task_list |
There was a problem hiding this comment.
This is good, but will also need a similar fn for %TaskList{name: "In Progress"} to make it the pull_requests list.
| TaskList | ||
| |> Repo.all() | ||
| |> Enum.each(&update_pr_column/1) | ||
|
|
There was a problem hiding this comment.
This could be condensed down to:
TaskList
|> Repo.all()
|> Enum.each(&update_done_column/1)
|> Enum.each(&update_pr_column/1)
|
I've used the migration script you wrote, Scott, and moved it's behavior into the migrations themselves. I did not get a chance to comment on the issues this PR resolves, so the instructions there do not match what I did, but I really feel this should be our preferable approach to handling migrations. The code that migrates the data uses schema names instead of our schema modules, so it's agnostic to our actual modules and works regardless of what the rest of our code looks like. Due to separate |
da90d36 to
3a48282
Compare
begedin
left a comment
There was a problem hiding this comment.
@snewcomer Great work. I made some changes to how migrations are done, worded a couple of your tests differently and cleaned up.
This is about done, so I'm approving your part from my end. @joshsmith can review and approve my part.
| test "defaults :pull_requests to 'false'" do | ||
| {:ok, record} = | ||
| %TaskList{} |> TaskList.changeset(@valid_attrs) |> Repo.insert | ||
| assert record.pull_requests == false |
There was a problem hiding this comment.
@snewcomer Your assertion here was refute record.pull_requests, but that one would have passed even if record.pull_requests == nil, so we want a more explicit one.
begedin
left a comment
There was a problem hiding this comment.
Just adding a blank "request changes" review here, so we don't accidentally merge before @joshsmith reviews.
c714aa5 to
03a06f0
Compare
| where: not is_nil(gi.github_pull_request_id), | ||
| update: [set: [task_list_id: ^pr_list_id]] | ||
| ) |> Repo.update_all([]) | ||
| end) |
There was a problem hiding this comment.
@joshsmith I really feel this is the way to go with migrations.
If our schema modules do not match the schemas in any migration step, the code will fail, but if we go like this, "schemaless", the only case where the migration step would not match the actual state of the schema were if we somehow run it manually, out of order, which would be incorrect usage of the migration.
I understand using actual schema modules and changesets in a seed script, but they should not be used in migrations.
There was a problem hiding this comment.
I really like this.
There was a problem hiding this comment.
Unfortunately it looks like this will override some of the work that was done in the earlier migration that moved tasks to closed, because this is not checking for whether the issues are closed.
There was a problem hiding this comment.
@joshsmith You are correct about checking for gi not closed. You could also check for task not closed, it would likely serve the same purpose, since presumably, the task is otherwise in sync with the issue.
On a similar note, my other migration should probably add a clause for archived. I'm not sure what the exact query would be, but it would likely involve a where: date_add(t.modified_at, 30, "day") > ^Date.utc_today somewhere in it.
I can't push the change myself due to not being home, but that should help.
| test "defaults :pull_requests to 'false'" do | ||
| {:ok, record} = | ||
| %TaskList{} |> TaskList.changeset(@valid_attrs) |> Repo.insert | ||
| assert record.pull_requests == false |
| |> Repo.insert | ||
|
|
||
| refute changeset.valid? | ||
| assert changeset |> Map.get(:errors) |> Keyword.get(:done) |
There was a problem hiding this comment.
minor spacing...unless its the GUI.
|
|
||
| create unique_index( | ||
| "task_lists", [:project_id], | ||
| where: "done = true", name: "task_lists_project_id_done_index") |
| where: not is_nil(gi.github_pull_request_id), | ||
| update: [set: [task_list_id: ^pr_list_id]] | ||
| ) |> Repo.update_all([]) | ||
| end) |
There was a problem hiding this comment.
I really like this.
| where: not is_nil(gi.github_pull_request_id), | ||
| update: [set: [task_list_id: ^pr_list_id]] | ||
| ) |> Repo.update_all([]) | ||
| end) |
There was a problem hiding this comment.
Unfortunately it looks like this will override some of the work that was done in the earlier migration that moved tasks to closed, because this is not checking for whether the issues are closed.
dff22be to
994f7f3
Compare
Fixes #1151, fixes #1152