Token导航 LogoToken导航TokenDH.com
前端设计敏感数据github未标认证来源可访问许可证需确认审计通过

postgres-test-setupPostgres 测试设置

Agent Skill

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

总安装

210

周安装

9

GitHub Stars

2

下载量

73
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/bmsuisse/skills --skill postgres-test-setup

简介

用于辅助数据库表结构、查询语句、迁移脚本和数据维护任务。

  • 适合分析 schema、编写 SQL、排查查询问题或生成索引优化建议。
  • 使用时需明确数据库类型和连接环境,区分只读分析与写入操作。
  • 涉及删除、更新、迁移或批量导入时,应优先 dry-run、备份或使用事务保护。
  • 建议在安装前确认与测试框架(如 Jest、Pytest)的集成方式,避免破坏现有测试流程。

SKILL.md

Postgres Test Setup

Spins up a Docker-based PostgreSQL instance, applies all SQL schema files from a database/ directory in dependency order, and seeds test data from .test_data.json sidecar files.


Quick reference

What do you need?Command
First-time setupFollow steps 1–5 below
Add a new tableCreate .sql + optional .test_data.json, then uv run -m test_server.start_postgres
Additive change (new column/index)Edit .sql, apply via run_sql.py, no reset needed
Breaking change (rename/drop column)Edit .sql, then uv run -m test_server.start_postgres --force-reset-db
Inspect test DB datauv run test_server/run_sql.py --sql "SELECT..." --results
Re-apply a function/viewuv run test_server/run_sql.py database/path/to/file.sql
Reset to clean slateuv run -m test_server.start_postgres --force-reset-db

Initial setup

1. Copy the scripts

Place scripts/start_postgres.py at test_server/start_postgres.py and scripts/run_sql.py at test_server/run_sql.py in the project.

Adjust the two constants at the top of start_postgres.py:

DOCKER_IMAGE = "pgvector/pgvector:pg18-trixie"  # or "postgres:17" without pgvector
DATABASE_DIR = "database"                        # folder with .sql files (relative to cwd)

ENV_PREFIX is auto-detected from [tool.pytest_env] in pyproject.toml by scanning for a key ending in POSTGRES_HOST (e.g. MDM_POSTGRES_HOST → prefix MDM_). Falls back to TEST_ if no match is found.

2. Add pytest dependencies

uv add --dev psycopg[binary] sqlglot docker pytest pytest-asyncio pytest-env
# if using pgvector:
uv add --dev pgvector

3. Configure pytest environment variables

In pyproject.toml:

[tool.pytest_env]
TEST_POSTGRES_PASSWORD = "testpwd"
TEST_POSTGRES_DB       = "app_test"
TEST_POSTGRES_USER     = "postgres"
TEST_POSTGRES_PORT     = "54324"
TEST_POSTGRES_HOST     = "localhost"

4. Add a session-scoped pytest fixture

In tests/conftest.py:

import os
import pytest_asyncio
from test_server.start_postgres import postgres_test_env, setup_database, start_postgres

@pytest_asyncio.fixture(scope="session", autouse=True)
async def ensure_test_postgres_server():
    for key, value in postgres_test_env.items():
        os.environ[key] = value
    start_postgres()
    await setup_database(force_reset_db=False)
    yield

5. Run manually (first-time or reset)

# Normal init (idempotent — skips tables already populated)
uv run -m test_server.start_postgres

# Full reset — drops and recreates the DB, re-inserts all test data
uv run -m test_server.start_postgres --force-reset-db

Making schema changes

All schema changes live in SQL files. Never alter the production or shared database directly.

When to reset vs. apply incrementally

Change typeApproach
New table or viewuv run -m test_server.start_postgres (picks up new files automatically)
New nullable column, new indexEdit .sql, apply via run_sql.py, no reset needed
Rename column, change type, drop columnEdit .sql, then run --force-reset-db

Workflow

1. Edit / create the relevant .sql file in database/
2. Apply to the local test DB:
   - Additive:  uv run test_server/run_sql.py database/path/to/file.sql
   - Breaking:  uv run -m test_server.start_postgres --force-reset-db
3. Run the tests to confirm nothing broke.

After verifying locally, a human applies the same SQL to production as a migration.

Adding a new table

  1. Create database/<schema>/tables/<table_name>.sql.
  2. Optionally create database/<schema>/tables/<table_name>.test_data.json with seed rows.
  3. Run uv run -m test_server.start_postgres — the new file is picked up automatically.

Executing SQL on the test database

run_sql.py auto-detects the env-var prefix from pyproject.toml and refuses to run if <PREFIX>POSTGRES_HOST is not localhost.

# Run a SQL file
uv run test_server/run_sql.py database/1_dim/tables/user.sql

# Run inline SQL
uv run test_server/run_sql.py --sql "SELECT * FROM dim.user LIMIT 10"

# Run inline SQL and print results as an ASCII table
uv run test_server/run_sql.py --sql "SELECT id, name FROM dim.user" --results

Results look like:

+----+-------+
| id | name  |
+----+-------+
| 1  | Alice |
| 2  | Bob   |
+----+-------+
(2 rows)

Never use run_sql.py to apply changes to production — it is locked to localhost by design.


Database directory layout

The script walks database/ and executes .sql files in this order:

PriorityDirectory/filename patternObject type
1schemaCREATE SCHEMA
2typesCustom types/enums
3tablesTables
4scalar_functionsScalar functions
5functionsFunctions
6viewsViews
7table_functionsTable functions
8proceduresProcedures
100permissionsGrants
101indexesIndexes

Files named all.sql, 100_permissions.sql, or containing .prod are skipped. Migration folders are skipped.

Cross-file foreign key dependencies are resolved automatically via sqlglot.

Recommended structure:

database/
├── 1_schema.sql
├── 0_public/
│   └── types/
│       └── my_enum.sql
├── 1_dim/
│   └── tables/
│       ├── user.sql
│       └── user.test_data.json      ← auto-loaded after user.sql
└── 100_permissions.sql              ← skipped by default

Test data files

Place a .test_data.json file next to any table .sql file — a JSON array of row objects:

[
  {"id": 1, "name": "Alice", "role": "admin"},
  {"id": 2, "name": "Bob",   "role": "reader"}
]
  • Nested dicts/lists are automatically serialised to JSON strings (for jsonb columns).
  • On --force-reset-db, rows are deleted and re-inserted.
  • On a normal run, a table is skipped if its row count already matches the JSON file.

Environment variables

VariableDefaultDescription
TEST_POSTGRES_HOSTlocalhostPostgres host
TEST_POSTGRES_PORT54324Host port (avoids conflict with 5432)
TEST_POSTGRES_DBapp_testDatabase name
TEST_POSTGRES_USERpostgresSuperuser
TEST_POSTGRES_PASSWORDtestpwdPassword
SKIP_START_POSTGRESSet to 1 to skip Docker startup (e.g. CI service containers)

CI / GitHub Actions

Skip Docker startup and point at a service container instead:

services:
  postgres:
    image: pgvector/pgvector:pg18-trixie
    env:
      POSTGRES_PASSWORD: testpwd
      POSTGRES_DB: app_test
      POSTGRES_USER: postgres
    ports:
      - 54324:5432

env:
  SKIP_START_POSTGRES: "1"
  TEST_POSTGRES_HOST: localhost
  TEST_POSTGRES_PORT: "54324"
  TEST_POSTGRES_DB: app_test
  TEST_POSTGRES_USER: postgres
  TEST_POSTGRES_PASSWORD: testpwd

Adapting for complex Postgres types

The included script handles simple columns and JSONB. If the project uses PostgreSQL composite types or custom enums that need psycopg adaptation, use the ComplexHelper class in references/complex_helper.py. Read that file for the full implementation and usage instructions — it shows how to extend insert_test_data to register custom types before inserting.

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

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

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

平台分布

Codex

35.82%
按下载量换算26

Claude

27.74%
按下载量换算20

Cursor

18.56%
按下载量换算14

Gemini CLI

8.14%
按下载量换算6

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

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

来源信息

继续浏览同类 Skills