sqlmodel-task-models
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.
When & Why to Use This Skill
This Claude skill provides a robust, type-safe, and async-compatible database schema for Todo applications using SQLModel. It is specifically optimized for PostgreSQL and ensures seamless integration with Better Auth, featuring automated timestamp management and relational integrity to streamline backend development and ensure data consistency.
Use Cases
- Developing a scalable Task Management API using SQLModel and FastAPI with full CRUD capabilities.
- Implementing a secure user authentication system compatible with Better Auth and PostgreSQL backends.
- Designing relational database models with built-in performance optimizations like strategic indexing on foreign keys.
- Automating database audit trails with standardized timestamp management for record creation and updates.
- Building type-safe Python applications that require strict relational integrity between users and their associated data.
| 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.