AgentSkillsCN

database

采用 Drizzle ORM 与 PostgreSQL 构建数据库模式。涵盖表结构定义、关系设置、迁移流程,以及 API 路由中的查询模式。当需要处理数据库表结构、编写查询语句、实施数据库迁移、调试数据库问题,或当用户提及 Drizzle、PostgreSQL、表、关系、迁移、表结构、SQL、数据库查询、事务、数据库操作、数据库错误、迁移失败,或连接问题时,可调用此技能。

SKILL.md
--- frontmatter
name: database
description: Database patterns using Drizzle ORM with PostgreSQL. Includes schema definitions, relations, migrations workflow, and querying patterns in API routes. Use when working with database schema, queries, migrations, debugging database issues, or when user mentions Drizzle, PostgreSQL, tables, relations, migrations, schema, SQL, database queries, transactions, DB operations, database errors, migration failures, or connection issues.
license: Unlicense

Database Patterns

Drizzle ORM with PostgreSQL (Neon serverless). All database code lives in server/database/.

Quick Reference

  • Schema: See schema-patterns.md for table definitions, foreign keys, enums, and JSON fields
  • Formatting: See formatting.md for Drizzle schema formatting rules
  • Relations: See relations.md for one-to-many and many-to-one patterns
  • Queries: See queries.md for select, insert, update, delete, and transactions
  • Migrations: See migrations.md for workflow and commands

Core Principles

  • Always use indexes on foreign keys
  • ULID primary keys with ulid() helper
  • Timestamps with timezone and auto-update
  • Use db from event.context in API routes
  • Validate with Valibot before DB operations
  • Guard clauses for auth checks
  • Transactions for multi-table operations