
- 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
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
"""Add categories table and category_id to todos
|
|
|
|
Revision ID: 003
|
|
Revises: 002
|
|
Create Date: 2025-06-18 10: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():
|
|
# Create categories table
|
|
op.create_table(
|
|
"categories",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("name", sa.String(100), nullable=False),
|
|
sa.Column("description", sa.String(500), nullable=True),
|
|
sa.Column("color", sa.String(7), nullable=True),
|
|
sa.Column(
|
|
"created_at",
|
|
sa.DateTime(timezone=True),
|
|
server_default=sa.text("CURRENT_TIMESTAMP"),
|
|
nullable=True,
|
|
),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.UniqueConstraint("name"),
|
|
)
|
|
op.create_index(op.f("ix_categories_id"), "categories", ["id"], unique=False)
|
|
|
|
# Add category_id column to todos table
|
|
op.add_column("todos", sa.Column("category_id", sa.Integer(), nullable=True))
|
|
op.create_foreign_key(
|
|
"fk_todos_category_id", "todos", "categories", ["category_id"], ["id"]
|
|
)
|
|
|
|
|
|
def downgrade():
|
|
# Remove foreign key and category_id column from todos
|
|
op.drop_constraint("fk_todos_category_id", "todos", type_="foreignkey")
|
|
op.drop_column("todos", "category_id")
|
|
|
|
# Drop categories table
|
|
op.drop_index(op.f("ix_categories_id"), table_name="categories")
|
|
op.drop_table("categories")
|