-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task unification todo task removal (#682)
* Add todo.step and todo.project data migration * Remove task from add_todolist_template * Remove task from IsAssociatedWithProject * Fix update_todos_from_todolist_template and tests * Fix auth * Remove task from worker_task_recent_todo_qas * Fix auth * Fix worker_task_recent_todo_qas * Fix auth * Remove unused code * Remove unused code * Fix todos/auth * Remove task from serializer * Fix tests * Remove unused code * Step should be slug * Add delete/destroy view * Remove task, pass step slug as one of args * Add helper * Fix api * Linting fix * Remove console.log * Update compiled js * Fix add_todolist_template usage * Fix tests * Fix tests after rebase * Fix tests * Simplify * Make it possible to get related todos via Task * Linting fixes * Fix tests * Clean-up and add comment * Add comments to migration * Rename reverse lookup name * Remove unused code * Clean tests * Rename module * Fix comment * Clean urls * Filter properly * Remove task__project and task__step from todo admin * Fix js formatting issue * Limit mmethods * Add missing method
- Loading branch information
Showing
24 changed files
with
378 additions
and
208 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Generated by Django 2.2.13 on 2020-09-04 14:49 | ||
|
||
|
||
from django.db import migrations | ||
from django.db.models import OuterRef | ||
from django.db.models import Subquery | ||
|
||
|
||
def fill_project_and_step_fields(apps, schema_editor): | ||
Step = apps.get_model('orchestra', 'Step') | ||
Project = apps.get_model('orchestra', 'Project') | ||
Todo = apps.get_model('orchestra', 'Todo') | ||
# This is the outer query field the querysets in the subqueries need to refer to | ||
o = OuterRef('id') | ||
# Select a step which has a task which has a todo which has an identical ID | ||
step_outerref_filter_qs = Step.objects.filter(tasks__todos__id=o) | ||
# Select a project which has a task which has a todo which has an identical ID | ||
project_outterref_filter_qs = Project.objects.filter(tasks__todos__id=o) | ||
# We need id value only. These will go as subqueries | ||
subq_step = step_outerref_filter_qs.values('id')[:1] | ||
subq_proj = project_outterref_filter_qs.values('id')[:1] | ||
# Update all todos | ||
Todo.objects.update(project=Subquery(subq_proj), step=Subquery(subq_step)) | ||
""" | ||
The query above generates the following SQL-query: | ||
UPDATE "orchestra_todo" | ||
SET "project_id" = ( | ||
SELECT u0."id" | ||
FROM "orchestra_project" U0 | ||
INNER JOIN "orchestra_task" U1 | ||
ON (u0."id" = u1."project_id") | ||
INNER JOIN "orchestra_todo" U2 | ||
ON (u1."id" = u2."task_id") | ||
WHERE u2."id" = ("orchestra_todo"."id") limit 1), | ||
"step_id" = ( | ||
SELECT u0."id" | ||
FROM "orchestra_step" u0 | ||
INNER JOIN "orchestra_task" u1 | ||
ON (u0."id" = u1."step_id") | ||
INNER JOIN "orchestra_todo" u2 | ||
ON (u1."id" = u2."task_id") | ||
WHERE u2."id" = ("orchestra_todo"."id") limit 1) | ||
WHERE "orchestra_todo"."is_deleted" = false;args=(false,) | ||
""" | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('orchestra', '0086_add_fields_to_todo'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(fill_project_and_step_fields, # manually-reviewed | ||
reverse_code=migrations.RunPython.noop), # manually-reviewed | ||
] |
19 changes: 19 additions & 0 deletions
19
orchestra/migrations/0088_change_related_name_todos_old.py
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,19 @@ | ||
# Generated by Django 2.2.13 on 2020-09-15 14:52 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('orchestra', '0087_todo_task_data_migration'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='todo', | ||
name='task', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='todos_deprecated', to='orchestra.Task'), | ||
), | ||
] |
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
Oops, something went wrong.