The todo schema provides flexible task management with multiple scheduling modes, Canvas LMS content linking, and nested subtasks.
Todo Table
Core task management table with support for various scheduling patterns and Canvas integration.
Schema Definition
Primary key - auto-generated UUID
Foreign key to user.id (cascade delete)
title
text
default: "\"\""
required
Task title or description
Extended task description or notes (optional)
checked
boolean
default: "false"
required
Whether the task is marked as complete
Scheduling Fields
Scheduling category for the task
Scheduled for a specific date/time during the day
Scheduled for evening of a specific date
Can be done anytime (default)
Future task without specific timeline
When to work on the task (used with calendar or calendarEvening date types)
Task deadline (optional, independent of scheduled date)
Subtasks
Array of nested subtasks stored as JSONB
Unique identifier for the subtask
Whether the subtask is complete
Canvas LMS Integration
Todos can be linked to Canvas LMS content for assignment tracking.
Type of Canvas content linked to this todo
Canvas discussion board post
Timestamp when task was marked complete (null if not completed)
createdAt
timestamp
default: "now()"
required
Task creation timestamp
updatedAt
timestamp
default: "now()"
required
Last update timestamp (auto-updates on modification)
Relationships
Belongs to user (cascade delete when user is removed)
Enums
Date Type Enum
export const dateTypeEnum = pgEnum ( "date_type" , [
"calendar" ,
"calendarEvening" ,
"anytime" ,
"someday" ,
]);
Canvas Content Type Enum
export const canvasContentTypeEnum = pgEnum ( "canvas_content_type" , [
"assignment" ,
"page" ,
"quiz" ,
"discussion" ,
]);
Type Exports
// Subtask type for JSONB storage
export type TodoSubTask = {
id : string ;
title : string ;
checked : boolean ;
};
// Inferred types from schema
export type Todo = typeof todo . $inferSelect ;
export type NewTodo = typeof todo . $inferInsert ;
Usage Examples
Creating a Simple Todo
await db . insert ( todo ). values ({
userId: "user_123" ,
title: "Complete homework" ,
dateType: "anytime" ,
});
Creating a Scheduled Todo with Due Date
await db . insert ( todo ). values ({
userId: "user_123" ,
title: "Team meeting" ,
dateType: "calendar" ,
scheduledDate: new Date ( "2026-03-10T14:00:00Z" ),
dueDate: new Date ( "2026-03-10T15:00:00Z" ),
});
Creating a Todo with Subtasks
await db . insert ( todo ). values ({
userId: "user_123" ,
title: "Research project" ,
subTasks: [
{ id: "1" , title: "Find sources" , checked: false },
{ id: "2" , title: "Write outline" , checked: false },
{ id: "3" , title: "Draft introduction" , checked: false },
],
});
Linking to Canvas Assignment
await db . insert ( todo ). values ({
userId: "user_123" ,
title: "Submit essay" ,
canvasContentType: "assignment" ,
canvasContentId: 12345 ,
canvasClassId: 67890 ,
dueDate: new Date ( "2026-03-15T23:59:00Z" ),
});
Database Configuration
Source: apps/web/src/db/schema/todo.ts
All foreign keys use { onDelete: "cascade" } to automatically remove todos when a user is deleted.