SQLModel Task Models

VerifiedSafe

Defines a type-safe SQLModel schema for a Todo app with User and Task models, including foreign keys, indexes, and timestamps. Optimized for PostgreSQL and compatible with Better Auth. Helps when needing a production-ready database layer with async support.

Sby Skills Guide Bot
DevelopmentIntermediate
706/2/2026
Claude Code
#sqlmodel#database-schema#todo-app#python#postgresql

Recommended for

Our review

This guide defines a robust, type-safe, async-compatible database schema for a Todo app using SQLModel, optimized for PostgreSQL and compatible with Better Auth.

Strengths

  • Clear User and Task model definitions with relationships
  • Strategic indexing for query performance
  • Automatic timestamp management
  • Follows SQLModel best practices for production readiness

Limitations

  • Does not cover database migrations or seeding
  • Models are Todo-specific and may need adaptation
  • Relies on SQLModel and its version compatibility
When to use it

When building a Todo app with SQLModel and PostgreSQL, needing a strong foundation for user-related task CRUD operations.

When not to use it

If using a different ORM (e.g., Django ORM, raw SQLAlchemy) or if the app does not require relational models.

Security analysis

Safe
Quality score88/100

The skill provides declarative guidance and code examples for SQLModel models without any executable commands, destructive operations, or data exfiltration.

No concerns found

Examples

Create SQLModel task schema
Define SQLModel models for a Todo app with User and Task tables, ensuring user_id foreign key, indexes on user_id and completed, and automatic timestamps. Compatible with Better Auth.
Add task model to existing project
I have a SQLModel project with User model already defined. Add a Task model with fields: title, description, completed, and a relationship to User. Include created_at and updated_at.
Optimize SQLModel schema for PostgreSQL
Write SQLModel models for a Todo app optimized for PostgreSQL. Use proper indexing, default values, and datetime.utcnow. Ensure compatibility with Better Auth user IDs as strings.

name: sqlmodel-task-models description: This skill should be used when defining a robust, type-safe, and async-compatible database schema for the Todo application using SQLModel, ensuring compatibility with Better Auth and optimized for PostgreSQL.

SQLModel Task Models

This skill providing guidance on defining a robust database schema using SQLModel for the Todo application.

Purpose

Defining a robust, type-safe, and async-compatible database schema for the Todo application using SQLModel, ensuring compatibility with Better Auth and optimized for PostgreSQL.

Capabilities

  • User Model: Schema aligned with Better Auth requirements.
  • Task Model: Full CRUD capability with relational mapping to Users.
  • Relational Integrity: Proper foreign key constraints and back-references.
  • Performance: Strategic indexing on user_id and completed fields.
  • Safety: Automated timestamp management (created_at, updated_at).

Implementation Details

Models Definition

from sqlmodel import SQLModel, Field, Relationship
from typing import List, Optional
from datetime import datetime

class User(SQLModel, table=True):
    id: str = Field(primary_key=True)
    email: str = Field(unique=True, index=True)
    name: Optional[str] = None
    created_at: datetime = Field(default_factory=datetime.utcnow)
    tasks: List["Task"] = Relationship(back_populates="user")

class Task(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    user_id: str = Field(foreign_key="user.id", index=True)
    title: str
    description: Optional[str] = None
    completed: bool = Field(default=False, index=True)
    created_at: datetime = Field(default_factory=datetime.utcnow)
    updated_at: datetime = Field(default_factory=datetime.utcnow)
    user: Optional[User] = Relationship(back_populates="tasks")

Best Practices

  • Using table=True for models that map to database tables.
  • Explicitly defining indexes for fields used in WHERE clauses (e.g., user_id, completed).
  • Using datetime.utcnow for consistent cross-region timestamping.
  • Keeping user_id as a string to match Better Auth's UUID/ID format.
Related skills