
- Add parent_id field to Todo model with self-referential foreign key - Add parent/children relationships and is_subtask property - Update TodoCreate/TodoUpdate schemas to include parent_id - Add subtasks list to Todo schema and create SubtaskCreate schema - Enhance get_todos CRUD function with parent_id filtering - Add subtask-specific CRUD functions: get_subtasks, create_subtask, move_subtask - Add API endpoints for subtask management - Create migration for adding parent_id column - Update imports and fix circular dependencies - Ensure proper cycle prevention and validation Features added: - GET /todos/{todo_id}/subtasks - Get all subtasks for a todo - POST /todos/{todo_id}/subtasks - Create a new subtask - PUT /subtasks/{subtask_id}/move - Move subtask or convert to main todo - Query parameter parent_id for filtering by parent - Query parameter include_subtasks for excluding subtasks from main list
44 lines
1020 B
Python
44 lines
1020 B
Python
"""Add subtasks support with parent_id field
|
|
|
|
Revision ID: 003
|
|
Revises: 002
|
|
Create Date: 2024-01-01 00:00:00.000000
|
|
|
|
"""
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = "003"
|
|
down_revision = "002"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.add_column(
|
|
"todos",
|
|
sa.Column("parent_id", sa.Integer(), nullable=True),
|
|
)
|
|
# Add foreign key constraint
|
|
op.create_foreign_key(
|
|
"fk_todos_parent_id",
|
|
"todos",
|
|
"todos",
|
|
["parent_id"],
|
|
["id"],
|
|
ondelete="CASCADE",
|
|
)
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
# Drop foreign key constraint first
|
|
op.drop_constraint("fk_todos_parent_id", "todos", type_="foreignkey")
|
|
# Drop the column
|
|
op.drop_column("todos", "parent_id")
|
|
# ### end Alembic commands ###
|