Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pull_requests && done to task_list #1157

Merged
merged 1 commit into from
Nov 6, 2017
Merged

Conversation

snewcomer
Copy link
Contributor

@snewcomer snewcomer commented Nov 6, 2017

  • done boolean
  • pull_requests boolean
  • script for modifying task_lists and project tasks
  • unique constraints for pairs of (project_id, inbox), (project_id, pull_requests), (project_id, done)

Fixes #1151, fixes #1152

@@ -52,7 +56,7 @@ defmodule CodeCorps.TaskList do

def create_changeset(struct, params) do
struct
|> cast(params, [:inbox])
|> cast(params, [:inbox, :done, :pull_requests])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would alpha-order here.

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)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this doing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

name: "In Progress",
position: 3
}, %{
inbox: false,
done: true,
name: "Done",
position: 4
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably remove inbox: false from the others here for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshsmith remove all inbox: false?

TaskList.create_changeset(task_list, %{done: true})
|> Repo.update()
end
defp update_done_column(task_list), do: task_list
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be condensed down to:

TaskList
|> Repo.all()
|> Enum.each(&update_done_column/1)
|> Enum.each(&update_pr_column/1)

@begedin
Copy link
Contributor

begedin commented Nov 6, 2017

@snewcomer @joshsmith

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 up and down steps, we are also able to rollback and I was able to test it using semi-real data (by syncing a mock repo and trying it out on that).

@begedin begedin force-pushed the task-list-modify branch 2 times, most recently from da90d36 to 3a48282 Compare November 6, 2017 11:20
Copy link
Contributor

@begedin begedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️

begedin
begedin previously requested changes Nov 6, 2017
Copy link
Contributor

@begedin begedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just adding a blank "request changes" review here, so we don't accidentally merge before @joshsmith reviews.

where: not is_nil(gi.github_pull_request_id),
update: [set: [task_list_id: ^pr_list_id]]
) |> Repo.update_all([])
end)
Copy link
Contributor

@begedin begedin Nov 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

@snewcomer snewcomer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

test "defaults :pull_requests to 'false'" do
{:ok, record} =
%TaskList{} |> TaskList.changeset(@valid_attrs) |> Repo.insert
assert record.pull_requests == false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️

|> Repo.insert

refute changeset.valid?
assert changeset |> Map.get(:errors) |> Keyword.get(:done)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor spacing...unless its the GUI.


create unique_index(
"task_lists", [:project_id],
where: "done = true", name: "task_lists_project_id_done_index")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!!

where: not is_nil(gi.github_pull_request_id),
update: [set: [task_list_id: ^pr_list_id]]
) |> Repo.update_all([])
end)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@joshsmith joshsmith merged commit 1ba8911 into develop Nov 6, 2017
@joshsmith joshsmith deleted the task-list-modify branch November 6, 2017 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add done boolean column to TaskList Add pull_requests boolean column to TaskList
3 participants