Skip to main content
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

id
text
required
Primary key - auto-generated UUID
userId
text
required
Foreign key to user.id (cascade delete)
title
text
default:"\"\""
required
Task title or description
description
text
Extended task description or notes (optional)
checked
boolean
default:"false"
required
Whether the task is marked as complete

Scheduling Fields

dateType
enum
default:"anytime"
Scheduling category for the task
calendar
enum
Scheduled for a specific date/time during the day
calendarEvening
enum
Scheduled for evening of a specific date
anytime
enum
Can be done anytime (default)
someday
enum
Future task without specific timeline
scheduledDate
timestamp
When to work on the task (used with calendar or calendarEvening date types)
dueDate
timestamp
Task deadline (optional, independent of scheduled date)

Subtasks

subTasks
jsonb
Array of nested subtasks stored as JSONB
id
string
required
Unique identifier for the subtask
title
string
required
Subtask title
checked
boolean
required
Whether the subtask is complete

Canvas LMS Integration

Todos can be linked to Canvas LMS content for assignment tracking.
canvasContentType
enum
Type of Canvas content linked to this todo
assignment
enum
Canvas assignment
page
enum
Canvas page content
quiz
enum
Canvas quiz
discussion
enum
Canvas discussion board post
canvasContentId
integer
Canvas content item ID
canvasClassId
integer
Canvas course ID

Metadata

completedAt
timestamp
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.

Build docs developers (and LLMs) love