-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pull_requests and done columns to task_list with migrations
- Loading branch information
Showing
8 changed files
with
265 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
priv/repo/migrations/20171106045740_add_done_to_task_list.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
defmodule CodeCorps.Repo.Migrations.AddDoneToTaskList do | ||
use Ecto.Migration | ||
|
||
import Ecto.Query | ||
|
||
alias CodeCorps.Repo | ||
|
||
def up do | ||
alter table(:task_lists) do | ||
add :done, :boolean, default: false | ||
end | ||
|
||
flush() | ||
|
||
from(tl in "task_lists", where: [name: "Done"], update: [set: [done: true]]) | ||
|> Repo.update_all([]) | ||
|
||
task_list_query = | ||
from(tl in "task_lists", where: [done: true], select: [:id]) | ||
|
||
# tests do not have any data, so we need to account for potential nil | ||
case task_list_query |> Repo.one do | ||
%{id: done_list_id} -> | ||
task_update_query = from t in "tasks", | ||
where: [status: "closed"], | ||
update: [set: [task_list_id: ^done_list_id]] | ||
task_update_query |> Repo.update_all([]) | ||
nil -> nil | ||
end | ||
end | ||
|
||
def down do | ||
alter table(:task_lists) do | ||
remove :done | ||
end | ||
end | ||
end |
54 changes: 54 additions & 0 deletions
54
priv/repo/migrations/20171106050209_add_pull_requests_to_task_list.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
defmodule CodeCorps.Repo.Migrations.AddPullRequestsToTaskList do | ||
use Ecto.Migration | ||
|
||
import Ecto.Query | ||
|
||
alias CodeCorps.Repo | ||
|
||
def up do | ||
alter table(:task_lists) do | ||
add :pull_requests, :boolean, default: false | ||
end | ||
|
||
flush() | ||
|
||
# set all "In Progress" task lists to now contain pull requests | ||
from( | ||
tl in "task_lists", | ||
where: [name: "In Progress"], | ||
update: [set: [pull_requests: true]] | ||
) |> Repo.update_all([]) | ||
|
||
# get projects paired with associated pull request task list as ids | ||
task_parent_data = from( | ||
p in "projects", | ||
left_join: | ||
tl in "task_lists", | ||
on: tl.project_id == p.id, | ||
where: tl.pull_requests == true, | ||
select: {p.id, tl.id} | ||
) |> Repo.all | ||
|
||
# get all tasks for projects, associated to github pull requests and | ||
# assign them to the pull request task list | ||
task_parent_data |> Enum.each(fn {project_id, pr_list_id} -> | ||
from( | ||
t in "tasks", | ||
where: [project_id: ^project_id], | ||
where: t.status != "closed", | ||
where: not is_nil(t.github_issue_id), | ||
inner_join: | ||
gi in "github_issues", | ||
on: t.github_issue_id == gi.id, | ||
where: not is_nil(gi.github_pull_request_id), | ||
update: [set: [task_list_id: ^pr_list_id]] | ||
) |> Repo.update_all([]) | ||
end) | ||
end | ||
|
||
def down do | ||
alter table(:task_lists) do | ||
remove :pull_requests | ||
end | ||
end | ||
end |
21 changes: 21 additions & 0 deletions
21
priv/repo/migrations/20171106103153_add_unique_constraints_to_specific_task_lists.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule CodeCorps.Repo.Migrations.AddUniqueConstraintsToSpecificTaskLists do | ||
@moduledoc false | ||
|
||
use Ecto.Migration | ||
|
||
def change do | ||
# There is already a "task_lists_project_id_index", so we name explicitly | ||
|
||
create unique_index( | ||
"task_lists", [:project_id], | ||
where: "done = true", name: "task_lists_project_id_done_index") | ||
|
||
create unique_index( | ||
"task_lists", [:project_id], | ||
where: "pull_requests = true", name: "task_lists_project_id_pull_requests_index") | ||
|
||
create unique_index( | ||
"task_lists", [:project_id], | ||
where: "inbox = true", name: "task_lists_project_id_inbox_index") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters