Todo (PostgreSQL)
This page documents the Todo schema for projects using PostgreSQL with Drizzle ORM.
The PostgreSQL implementation leverages strong types and relational integrity to provide a secure and efficient task management foundation.
This schema relies on the users table from the Auth Domain. The userId field is configured with a foreign key constraint and onDelete: 'cascade'.
Installation Guide
To add this schema to your project, run:
npx servercn-cli add schema todoDuring initialization, ensure you select PostgreSQL when prompted for the database.
Database Design
To see the complete database design, including the User schema from the Auth Domain, please click here visualization.
If you install schema one by one (such as auth/user and auth/session), the relationships between them won’t be automatic—you’ll need to implement them manually.
1. User Schema
The User Schema is the core component for storing user identity, credentials, and profile information.
File Path: src/drizzle/schemas/user.schema.ts
2. Todo Schema
The Todo Schema defines the structure of your tasks in PostgreSQL.
File Path: src/drizzle/schemas/todo.schema.ts
Installation:
npx servercn-cli add schema todo/todo3. schema.helper.ts
src/drizzle/schemas/schema.helper.ts
4. Export all schemas
ssrc/drizzle/index.ts
5. drizzle.config.ts
drizzle.config.ts
Relational Design
Explicit relations make data fetching much simpler and more expressive:
src/drizzle/schemas/user.schema.ts
src/drizzle/schemas/todo.schema.ts
If you install schema one by one (such as auth/user and auth/session), the relationships between them won’t be automatic—you’ll need to implement them manually.