Files
FabledScribe/alembic/versions/0004_merge_tasks_into_notes.py
T
bvandeusen 807cde30be Merge tasks into notes: a task is just a note with task attributes
A task is now a note with status/priority/due_date columns set (status IS NOT NULL).
This eliminates the separate tasks table, companion note system, cascade deletes,
bidirectional title sync, and _skip_cascade flags.

Migration (0004):
- Add status, priority, due_date columns to notes table
- Migrate task data from companion notes and orphan tasks
- Drop tasks table and old enum types

Backend:
- models/note.py: Add TaskStatus/TaskPriority enums, task columns, is_task property
- models/task.py: Deleted (merged into note.py)
- models/__init__.py: Re-export enums from note.py, remove Task import
- services/notes.py: Remove companion/cascade logic, add is_task filter,
  convert_note_to_task, convert_task_to_note, simplified backlinks
- services/tasks.py: Rewritten as thin wrappers around notes service
- routes/notes.py: Add is_task filter (default false), task fields in CRUD,
  convert-to-note endpoint
- routes/tasks.py: description→body (with fallback), remove note_id filter

Frontend:
- types/note.ts: Add TaskStatus, TaskPriority, task fields to Note interface
- types/task.ts: Task is now a re-export alias for Note
- stores/notes.ts: Simplify convertToTask, add convertToNote
- stores/tasks.ts: description→body in createTask/updateTask
- TaskEditorView: description→body, remove companion note UI
- TaskViewerView: description→body, remove companion note link, add Convert to Note
- NoteViewerView: Remove companion task UI, simplify convert-to-task
- TaskCard: description→body, non-null assertions for status/priority

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 17:56:12 -05:00

61 lines
1.9 KiB
Python

"""merge tasks into notes table
Revision ID: 0004
Revises: 0003
Create Date: 2025-01-01 00:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
revision = "0004"
down_revision = "0003"
branch_labels = None
depends_on = None
def upgrade() -> None:
# Add task columns to notes table
op.add_column("notes", sa.Column("status", sa.Text(), nullable=True))
op.add_column("notes", sa.Column("priority", sa.Text(), nullable=True))
op.add_column("notes", sa.Column("due_date", sa.Date(), nullable=True))
op.create_index("ix_notes_status", "notes", ["status"])
conn = op.get_bind()
# Migrate tasks that have companion notes:
# Copy status/priority/due_date to the companion note,
# and merge the task description into the note body if the note body is empty.
conn.execute(sa.text("""
UPDATE notes
SET status = t.status,
priority = t.priority,
due_date = t.due_date,
body = COALESCE(NULLIF(t.description, ''), notes.body),
tags = CASE
WHEN array_length(t.tags, 1) IS NOT NULL THEN t.tags
ELSE notes.tags
END
FROM tasks t
WHERE t.note_id = notes.id
"""))
# Handle orphan tasks (note_id IS NULL) — insert them as new notes
conn.execute(sa.text("""
INSERT INTO notes (title, body, tags, status, priority, due_date, created_at, updated_at)
SELECT title, description, tags, status, priority, due_date, created_at, updated_at
FROM tasks
WHERE note_id IS NULL
"""))
# Drop tasks table and its indexes
op.drop_table("tasks")
# Drop the old enum types that are no longer used by any table
op.execute("DROP TYPE IF EXISTS task_status")
op.execute("DROP TYPE IF EXISTS task_priority")
def downgrade() -> None:
raise NotImplementedError("Downgrade not supported for this migration")