Token导航 LogoToken导航TokenDH.com
开发只读github未标认证来源可访问许可证需确认审计通过

howto-develop-with-postgreshowto develop with Postgres 开发

Agent Skill

用于辅助数据库表结构、查询语句、迁移脚本和数据维护任务。它适合让 Agent 分析 schema、编写 SQL、排查查询问题、整理索引或生成迁移建议。使用时需要明确数据库类型、连接环境和目标表,区分只读分析与写入变更;涉及删除、更新、迁移和批量导入时,应优先 dry-run、备份或事务保护,避免误操作。

总安装

267

周安装

11

GitHub Stars

176

下载量

87
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

请帮我安装这个 Agent Skill:howto-develop-with-postgres(howto develop with Postgres 开发)
来源仓库:https://github.com/ed3dai/ed3d-plugins
仓库路径:skills/howto-develop-with-postgres
安装命令:
npx skills add https://github.com/ed3dai/ed3d-plugins --skill howto-develop-with-postgres
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/ed3dai/ed3d-plugins --skill howto-develop-with-postgres

简介

用于辅助 PostgreSQL 数据库的表结构、查询语句和迁移脚本开发。

  • 适合分析 schema、编写 SQL、排查查询问题或生成索引建议。
  • 使用时需明确数据库类型、连接环境和目标表,区分只读与写入操作。
  • 涉及删除、更新或批量导入时,应优先进行 dry-run 或事务保护。
  • 操作前务必做好数据备份,避免误操作导致数据丢失。

SKILL.md

PostgreSQL Development Patterns

Overview

Enforce transaction safety, type safety, and naming conventions to prevent data corruption and runtime errors.

Core principles:

  • Transactions prevent partial updates (data corruption)
  • Type safety catches errors at compile time
  • Naming conventions ensure consistency
  • Read-write separation prevents accidental mutations

For TypeScript/Drizzle implementations: See typescript-drizzle.md for concrete patterns.

Transaction Management

TX_ Prefix Rule (STRICT ENFORCEMENT)

Methods that START transactions:

  • Prefix method name with TX_
  • Must NOT accept connection/executor parameter
  • Call connection.transaction() or db.transaction() internally

Methods that PARTICIPATE in transactions:

  • No TX_ prefix
  • MUST accept connection/executor parameter with default value
  • Execute queries using the provided executor
// GOOD: Starts transaction, has TX_ prefix, no executor parameter
async TX_createUserWithProfile(userData: UserData, profileData: ProfileData): Promise<User> {
  return this.db.transaction(async (tx) => {
    const user = await this.createUser(userData, tx);
    await this.createProfile(user.id, profileData, tx);
    return user;
  });
}

// GOOD: Participates in transaction, no TX_ prefix, takes executor
async createUser(userData: UserData, executor: Drizzle = this.db): Promise<User> {
  return executor.insert(USERS).values(userData).returning();
}

// BAD: Starts transaction but missing TX_ prefix
async createUserWithProfile(userData: UserData, profileData: ProfileData): Promise<User> {
  return this.db.transaction(async (tx) => { /* ... */ });
}

// BAD: Has TX_ prefix but takes executor parameter (allows nesting)
async TX_createUser(userData: UserData, executor: Drizzle = this.db): Promise<User> {
  return executor.transaction(async (tx) => { /* ... */ });
}

What DOES NOT count as "starting a transaction":

  • Single INSERT/UPDATE/DELETE operations
  • Atomic operations like onConflictDoUpdate
  • SELECT queries

Type Safety

Primary Keys

Default: ULID stored as UUID

  • When in doubt, use ULID: "Most things can leak in some way"
  • Prevents ID enumeration attacks
  • Time-sortable for indexing efficiency

Exceptions (context-dependent):

  • Pure join tables (composite PK from both FKs)
  • Small lookup tables (serial/identity acceptable)
  • Internal-only tables with no user visibility (serial/identity acceptable)

Rule: If unsure whether data will be user-visible, use ULID.

Financial Data

Use exact decimal types (numeric/decimal) for monetary values:

  • Never use float/double for money (causes rounding errors)
  • Use numeric/decimal with appropriate precision and scale
  • Example: numeric(19, 4) for general financial data

Why: Floating-point types accumulate rounding errors. Exact decimal types prevent financial discrepancies.

JSONB Columns

ALWAYS type JSONB columns in your ORM/schema:

  • Use typed schema when structure is known
  • Use Record<string, unknown> if truly schemaless
  • Never leave JSONB untyped

Why: Prevents runtime errors from accessing undefined properties or wrong types.

Read-Write Separation

Maintain separate client types at compile time:

  • Read-write client: Full mutation capabilities
  • Read-only client: Mutation methods removed at type level
  • Default to read-only for query methods
  • Use read-write only when mutations needed

Why: Prevents accidental writes to replica, enforces deliberate mutation choices.

Naming Conventions

Database Identifiers

All database objects use snake_case:

  • Tables: user_preferences, order_items
  • Columns: created_at, user_id, is_active
  • Indexes: idx_tablename_columns (e.g., idx_users_email)
  • Foreign keys: fk_tablename_reftable (e.g., fk_orders_users)

Application code: Map to idiomatic case (camelCase in TypeScript, etc.)

Schema Patterns

Standard mixins:

  • created_at, updated_at timestamps on all tables
  • deleted_at for soft deletion when needed
  • tenant_id for multi-tenant tables (project-dependent)

Proactive indexing:

  • All foreign key columns
  • Columns used in WHERE clauses
  • Columns used in JOIN conditions
  • Columns used in ORDER BY

Concurrency

Default isolation (Read Committed) for most operations.

Use stricter isolation when:

  • Financial operations: Serializable isolation
  • Inventory/count operations: Serializable isolation
  • Critical sections: Pessimistic locking (SELECT... FOR UPDATE)

Migrations

Always use generate + migrate workflow:

  1. Change schema in code
  2. Generate migration file
  3. Review migration SQL
  4. Apply migration to database

Never use auto-push workflow in production.

Common Mistakes

MistakeRealityFix
"This is one operation, doesn't need transaction"Multi-step operations without transactions cause partial updates and data corruptionWrap in transaction with TX_ prefix
"Single atomic operation needs TX_ prefix"TX_ is for explicit transaction blocks, not atomic operationsNo TX_ for single INSERT/UPDATE/DELETE
"UUID is just a string"Type confusion causes runtime errors (wrong ID formats, failed lookups)Use strict UUID type in language
"I'll type JSONB later when schema stabilizes"Untyped JSONB leads to undefined property access and type errorsType immediately with known fields or Record<string, unknown>
"Read client vs write client doesn't matter"Using wrong client bypasses separation, allows accidental mutationsUse read-only client by default, switch deliberately
"I'll add indexes when we see performance issues"Missing indexes on foreign keys cause slow queries from day oneAdd indexes proactively for FKs and common filters
"This table won't be user-visible, use serial"Requirements change, IDs leak in logs/URLs/errorsUse ULID by default unless certain it's internal-only
"Float/double is fine for money, close enough"Rounding errors accumulate, causing financial discrepancies (0.01 differences multiply)Use numeric/decimal types for exact arithmetic

Red Flags - STOP and Refactor

Transaction management:

  • Method calls .transaction() but no TX_ prefix
  • Method has TX_ prefix but accepts executor parameter
  • Multi-step operation without transaction wrapper

Type safety:

  • JSONB column without type annotation
  • UUID/ULID stored as plain string type
  • No separation between read and write clients
  • Float/double types for monetary values

Schema:

  • Missing indexes on foreign keys
  • No created_at/updated_at timestamps
  • camelCase or PascalCase in database identifiers

All of these mean: Stop and fix immediately.

Reference

For TypeScript/Drizzle concrete implementations: typescript-drizzle.md

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

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

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

平台分布

Codex

35.01%
按下载量换算30

Claude

30.35%
按下载量换算26

Cursor

20.38%
按下载量换算18

Gemini CLI

9.52%
按下载量换算8

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

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

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills