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 building a Todo app with SQLModel and PostgreSQL, needing a strong foundation for user-related task CRUD operations.
If using a different ORM (e.g., Django ORM, raw SQLAlchemy) or if the app does not require relational models.
Security analysis
SafeThe skill provides declarative guidance and code examples for SQLModel models without any executable commands, destructive operations, or data exfiltration.
No concerns found
Examples
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.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.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_idandcompletedfields. - 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=Truefor models that map to database tables. - Explicitly defining indexes for fields used in
WHEREclauses (e.g.,user_id,completed). - Using
datetime.utcnowfor consistent cross-region timestamping. - Keeping
user_idas a string to match Better Auth's UUID/ID format.
Next.js App Router Expert
Development
A skill that turns Claude into a Next.js App Router expert.
README Generator
Development
Creates professional and comprehensive README.md files for your projects.
API Documentation Writer
Development
Generates comprehensive API documentation in OpenAPI/Swagger format.