Token导航 LogoToken导航TokenDH.com
开发只读github未标认证来源可访问clear审计异常

sqlmodel-expertsql 模型专家

Agent Skill

sqlmodel-expert 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

2,328

周安装

99

GitHub Stars

1

下载量

816
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:sqlmodel-expert(sql 模型专家)
来源仓库:https://github.com/bilalmk/todo_correct
仓库路径:skills/sqlmodel-expert
安装命令:
npx skills add https://github.com/bilalmk/todo_correct --skill sqlmodel-expert
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/bilalmk/todo_correct --skill sqlmodel-expert

简介

用于处理 GitHub 仓库、Issue 和 Pull Request 等协作信息。

  • 适合在需要围绕代码变更或协作事项进行整理时使用。
  • 通过命令行工具获取仓库元数据和任务状态。
  • 安装前建议确认是否具备访问目标仓库的权限。
  • sqlmodel-expert 属于开发类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

SQLModel Expert

Advanced SQLModel patterns and comprehensive Alembic migrations for production databases.

Quick Start

Define a Basic Model

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

class Task(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    title: str = Field(index=True)
    description: Optional[str] = None
    completed: bool = Field(default=False)
    created_at: datetime = Field(default_factory=datetime.utcnow)

Initialize Database

# Using provided script
python scripts/init_db.py --url postgresql://user:pass@localhost/db

# Or manually
from sqlmodel import create_engine
engine = create_engine("postgresql://user:pass@localhost/db")
SQLModel.metadata.create_all(engine)

Create Migration

# Using provided helper script
./scripts/migrate.sh create "add user table"

# Or directly with Alembic
alembic revision --autogenerate -m "add user table"
alembic upgrade head

Core Topics

1. Advanced Model Patterns

See: references/advanced-models.md

  • Relationships: One-to-many, many-to-many, self-referential
  • Inheritance: Single table, joined table, polymorphism
  • Validation: Pydantic validators, custom constraints
  • Mixins: Timestamp, soft delete, reusable patterns
  • Field Types: Enums, JSON, arrays, custom types
  • Indexes: Single, composite, partial indexes
  • Constraints: Unique, check, foreign key cascades

2. Comprehensive Migrations

See: references/migrations.md

  • Alembic Setup: Configuration, env.py for SQLModel
  • Creating Migrations: Autogenerate vs manual
  • Schema Changes: Add/drop columns, rename, change types
  • Data Migrations: Complex data transformations
  • Production Workflow: Zero-downtime migrations
  • Rollback Strategies: Safe downgrade patterns
  • Troubleshooting: Common issues and solutions

3. Query Optimization

See: references/queries-optimization.md

  • N+1 Problem: Solutions with eager loading
  • Query Patterns: Joins, aggregations, subqueries
  • Performance: Indexes, batch operations, profiling
  • Advanced Queries: Window functions, CTEs
  • Bulk Operations: Insert, update, delete at scale
  • Testing: Query counting, explain analyze

Common Patterns

One-to-Many Relationship

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

class Team(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    name: str

    # One team has many heroes
    heroes: List["Hero"] = Relationship(back_populates="team")

class Hero(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    name: str
    team_id: Optional[int] = Field(foreign_key="team.id")

    # Many heroes belong to one team
    team: Optional[Team] = Relationship(back_populates="heroes")

Many-to-Many with Link Table

class HeroTeamLink(SQLModel, table=True):
    hero_id: int = Field(foreign_key="hero.id", primary_key=True)
    team_id: int = Field(foreign_key="team.id", primary_key=True)
    joined_at: datetime = Field(default_factory=datetime.utcnow)

class Hero(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    name: str
    teams: List["Team"] = Relationship(
        back_populates="heroes",
        link_model=HeroTeamLink
    )

class Team(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    name: str
    heroes: List[Hero] = Relationship(
        back_populates="teams",
        link_model=HeroTeamLink
    )

Solving N+1 Query Problem

from sqlalchemy.orm import selectinload

# BAD - N+1 queries
users = session.exec(select(User)).all()
for user in users:
    posts = user.posts  # Each triggers a query!

# GOOD - Eager loading (2 queries total)
statement = select(User).options(selectinload(User.posts))
users = session.exec(statement).all()
for user in users:
    posts = user.posts  # No additional query!

Creating a Migration

# 1. Modify your model
class User(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    email: str
    phone: str  # New field added

# 2. Generate migration
# alembic revision --autogenerate -m "add phone to user"

# 3. Review generated migration
def upgrade() -> None:
    op.add_column('user', sa.Column('phone', sa.String(), nullable=True))

def downgrade() -> None:
    op.drop_column('user', 'phone')

# 4. Apply migration
# alembic upgrade head

Migration Helper Scripts

Initialize Database

python scripts/init_db.py --url postgresql://user:pass@localhost/db

Migration Operations

./scripts/migrate.sh init              # Initialize Alembic
./scripts/migrate.sh create "message"  # Create migration
./scripts/migrate.sh upgrade           # Apply migrations
./scripts/migrate.sh downgrade         # Rollback one
./scripts/migrate.sh current           # Show current
./scripts/migrate.sh history           # Show history
./scripts/migrate.sh test              # Test up & down

Example Models

Use the example models in assets/example-models.py as templates:

  • User model with timestamp mixin
  • Task model with enums and relationships
  • Team model with many-to-many
  • Tag system with link tables
  • Separate read/write/update models

Copy to your project:

cp assets/example-models.py your-project/app/models.py

Best Practices Checklist

Model Design

  • Use type hints for all fields
  • Separate read/write/update models
  • Use mixins for common fields (timestamps, soft delete)
  • Define indexes on foreign keys and frequently queried columns
  • Use enums for constrained choices
  • Implement proper validation with Pydantic validators

Relationships

  • Use back_populates for bidirectional relationships
  • Create explicit link tables for many-to-many
  • Consider cascade delete behavior
  • Use eager loading to prevent N+1 queries
  • Index foreign key columns

Migrations

  • Always review autogenerated migrations
  • One logical change per migration
  • Test both upgrade and downgrade
  • Use descriptive migration names
  • Never edit applied migrations
  • Add data migrations when changing schemas
  • Backup database before production migrations

Query Optimization

  • Use eager loading (selectinload) for relationships
  • Select only needed columns
  • Use indexes for WHERE/ORDER BY columns
  • Batch operations instead of loops
  • Profile slow queries
  • Use connection pooling

Troubleshooting Guide

Migration Issues

Problem: Alembic doesn't detect model changes

# Solution: Ensure models are imported in env.py
from app.models import User, Task, Team  # Import all models
target_metadata = SQLModel.metadata

Problem: Failed migration

# Check current state
alembic current

# Manually fix issue, then stamp
alembic stamp head

# Or downgrade and retry
alembic downgrade -1
alembic upgrade head

Query Performance

Problem: Slow queries

# Enable query logging
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)

# Use EXPLAIN ANALYZE
explain = session.exec(text("EXPLAIN ANALYZE SELECT ...")).all()

# Profile queries
# See references/queries-optimization.md for detailed patterns

Problem: N+1 queries

# Use selectinload
statement = select(User).options(selectinload(User.posts))

# Or joinedload
from sqlalchemy.orm import joinedload
statement = select(User).options(joinedload(User.posts))

Production Workflow

Development

  1. Modify SQLModel models
  2. Generate migration: ./scripts/migrate.sh create "description"
  3. Review generated migration file
  4. Test migration: ./scripts/migrate.sh test
  5. Commit migration file

Staging

  1. Deploy application code
  2. Run migrations: alembic upgrade head
  3. Verify data integrity
  4. Test application

Production

  1. Backup database: pg_dump mydb > backup.sql
  2. Deploy in maintenance window
  3. Run migrations: alembic upgrade head
  4. Monitor logs and metrics
  5. Verify application functionality

Zero-Downtime Migration Strategy

For large production databases:

# Phase 1: Add new column (nullable)
def upgrade():
    op.add_column('user', sa.Column('new_email', sa.String(), nullable=True))

# Deploy app version that writes to both columns

# Phase 2: Backfill data
def upgrade():
    op.execute("UPDATE user SET new_email = email WHERE new_email IS NULL")

# Phase 3: Make non-nullable
def upgrade():
    op.alter_column('user', 'new_email', nullable=False)

# Deploy app version that reads from new column

# Phase 4: Drop old column
def upgrade():
    op.drop_column('user', 'email')

Additional Resources

  • Advanced Patterns: See references/advanced-models.md for inheritance, polymorphism, composite keys
  • Migration Guide: See references/migrations.md for Alembic mastery
  • Query Optimization: See references/queries-optimization.md for performance tuning

This skill provides everything needed for professional SQLModel development and database management.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

28.32%
按下载量换算231

Gemini CLI

20.9%
按下载量换算171

OpenCode

17.18%
按下载量换算140

Antigravity

10.78%
按下载量换算88

github-copilot

7.46%
按下载量换算61

Codex

3.45%
按下载量换算28

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

未通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。

来源信息

继续浏览同类 Skills