Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计提醒

managing-database-tests管理数据库测试

Agent Skill

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

总安装

564

周安装

24

GitHub Stars

2,124

下载量

198
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

请帮我安装这个 Agent Skill:managing-database-tests(管理数据库测试)
来源仓库:https://github.com/jeremylongshore/claude-code-plugins-plus-skills
仓库路径:skills/managing-database-tests
安装命令:
npx skills add https://github.com/jeremylongshore/claude-code-plugins-plus-skills --skill managing-database-tests
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/jeremylongshore/claude-code-plugins-plus-skills --skill managing-database-tests

简介

用于辅助数据库表结构、查询语句和迁移脚本编写。

  • 适合分析 schema、排查查询问题或生成迁移建议。
  • 使用时需明确数据库类型、连接环境和目标表。managing-database-tests 属于研究检索类 Skill,可作为该场景下的辅助能力补充。
  • 涉及删除、更新或批量导入时应优先 dry-run 或事务保护。
  • 建议避免误操作,确保有备份机制后再执行写入变更。

SKILL.md

Database Test Manager

Overview

Manage database testing including fixture loading, transaction-based test isolation, migration validation, query performance testing, and data integrity checks. Supports PostgreSQL, MySQL, MongoDB, SQLite (in-memory), and Redis with ORM-agnostic patterns for Prisma, TypeORM, SQLAlchemy, Knex, and Drizzle.

Prerequisites

  • Database instance available for testing (Docker container, in-memory SQLite, or dedicated test server)
  • Database client library and ORM installed (Prisma, TypeORM, Knex, SQLAlchemy, etc.)
  • Migration files up to date and tested independently
  • Test database connection string configured in environment (distinct from development/production)
  • Database seed data scripts for baseline test state

Instructions

  1. Set up the test database infrastructure:

- Use Docker to spin up a dedicated test database: docker run -d -p 5433:5432 --name test-db postgres:16-alpine. - Or use SQLite in-memory mode for fast unit tests: sqlite::memory:. - Or use Testcontainers for ephemeral database per test suite. - Verify the test database is isolated from development data.

  1. Run database migrations against the test database:

- Execute npx prisma migrate deploy or npx knex migrate:latest --env test. - Verify all migrations apply cleanly to an empty database. - Test rollback: run migrate:rollback and verify schema reverts correctly.

  1. Implement test isolation strategy (choose one):

- Transaction rollback: Wrap each test in a transaction; roll back after assertions. Fastest option. - Truncation: Truncate all tables in beforeEach. Simpler but slower. - Database recreation: Drop and recreate the database before each test suite. Slowest, most thorough.

  1. Create database fixture utilities:

- Factory functions that insert records and return the created entity with its database-generated ID. - Seed functions for standard test scenarios (empty state, populated state, edge cases). - Cleanup utilities that handle foreign key ordering for truncation.

  1. Write database-specific test cases:

- CRUD operations: Insert, query, update, delete records and verify database state. - Constraint validation: Attempt invalid inserts (null on NOT NULL, duplicate on UNIQUE) and verify rejection. - Referential integrity: Verify cascading deletes, foreign key enforcement, and orphan prevention. - Index performance: Verify queries use expected indexes with EXPLAIN ANALYZE. - Transaction isolation: Test concurrent updates and verify conflict handling.

  1. Test database query performance:

- Run EXPLAIN ANALYZE on critical queries and assert expected index usage. - Benchmark query execution time with representative data volumes. - Flag queries doing sequential scans on large tables.

  1. Validate migration safety:

- Test each migration can run on a populated database without data loss. - Verify backward compatibility (old code works with new schema during rollout). - Check migration execution time is acceptable for production deployment.

Output

  • Database test files organized by entity in tests/database/ or tests/models/
  • Fixture and factory utility files in tests/helpers/ or tests/factories/
  • Migration test scripts validating up/down migrations
  • Query performance benchmarks with EXPLAIN ANALYZE output
  • Test database Docker Compose configuration

Error Handling

ErrorCauseSolution
Foreign key constraint violation during cleanupTruncation order does not respect foreign key dependenciesTruncate tables in reverse dependency order; or disable FK checks during cleanup (SET CONSTRAINTS ALL DEFERRED)
Connection pool exhaustedToo many test workers opening separate connectionsUse a single shared connection for tests; limit pool size; close connections in afterAll
Migration fails on test databaseSchema drift between development and test databasesDrop and recreate test database; run all migrations from scratch; verify migration checksums
Transaction rollback does not clean upORM auto-commits or test creates a new connection outside the transactionInject the transaction connection into all ORM operations; disable auto-commit in test config
Slow test suite due to database I/OToo many INSERT/DELETE operations per testUse in-memory SQLite for unit tests; batch seed data; use transaction rollback instead of truncation

Examples

Jest with Prisma transaction rollback:

import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

describe('UserRepository', () => {
  afterAll(async () => { await prisma.$disconnect(); });

  it('creates and retrieves a user', async () => {
    await prisma.$transaction(async (tx) => {
      const created = await tx.user.create({
        data: { name: 'Alice', email: 'alice@test.com' },
      });
      const found = await tx.user.findUnique({ where: { id: created.id } });
      expect(found).toMatchObject({ name: 'Alice', email: 'alice@test.com' });
      // Transaction rolls back automatically when we throw
      throw new Error('ROLLBACK');
    }).catch((e) => {
      if (e.message !== 'ROLLBACK') throw e;
    });
  });
});

pytest with database fixture and rollback:

import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import Session

@pytest.fixture
def db_session():
    engine = create_engine("postgresql://test:test@localhost:5433/testdb")  # 5433 = configured value
    connection = engine.connect()
    transaction = connection.begin()
    session = Session(bind=connection)
    yield session
    session.close()
    transaction.rollback()
    connection.close()

def test_insert_and_query_user(db_session):
    db_session.execute(
        text("INSERT INTO users (name, email) VALUES (:n, :e)"),
        {"n": "Alice", "e": "alice@test.com"}
    )
    result = db_session.execute(text("SELECT name FROM users WHERE email = :e"),
                                 {"e": "alice@test.com"}).fetchone()
    assert result[0] == "Alice"

Migration validation test:

describe('Database Migrations', () => {
  it('applies all migrations to empty database', async () => {
    const result = await exec('npx prisma migrate deploy');
    expect(result.exitCode).toBe(0);
  });

  it('migration is idempotent', async () => {
    await exec('npx prisma migrate deploy');
    const result = await exec('npx prisma migrate deploy');
    expect(result.exitCode).toBe(0); // Second run should succeed (no-op)
  });
});

Resources

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

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

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

平台分布

Codex

33.66%
按下载量换算67

Claude

31.12%
按下载量换算62

Cursor

17.5%
按下载量换算35

Gemini CLI

8.56%
按下载量换算17

安全审计

Gen Agent Trust Hub

可疑

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

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

来源信息

继续浏览同类 Skills