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

comparing-database-schemas比较数据库模式

Agent Skill

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

总安装

649

周安装

26

GitHub Stars

2,133

下载量

210
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

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

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

简介

comparing-database-schemas 用于跨环境数据库结构差异分析,支持 PostgreSQL 与 MySQL。

  • 自动提取 schema-only 脚本并生成可读比对报告,指导迁移工作。
  • 通过 GitHub 安装,使用 npx skills add 命令添加指定仓库中的技能。
  • 安装前需确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写操作。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Database Diff Tool

Overview

Compare database schemas between two environments (development vs. staging, staging vs.

Prerequisites

  • Connection credentials to both source and target databases
  • psql or mysql CLI configured to connect to both environments
  • Read access to information_schema and pg_catalog (PostgreSQL) or information_schema (MySQL)
  • Permission to run pg_dump --schema-only for full schema extraction
  • Understanding of which environment is the "source of truth" (typically the migration-managed environment)

Instructions

  1. Extract the full schema from both databases for comparison:

- PostgreSQL: pg_dump --schema-only --no-owner --no-privileges -f schema_source.sql source_db and repeat for target_db - MySQL: mysqldump --no-data --routines --triggers source_db > schema_source.sql - Alternatively, query information_schema directly for programmatic comparison

  1. Compare tables present in each database:

- SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_catalog = 'source_db' EXCEPT SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_catalog = 'target_db' - This reveals tables that exist in source but not in target (and vice versa)

  1. Compare columns for each shared table:

- Query information_schema.columns from both databases for: column_name, data_type, character_maximum_length, is_nullable, column_default, ordinal_position - Flag differences in data type, nullability, default values, and column ordering - Detect added columns (in source, not target) and dropped columns (in target, not source)

  1. Compare indexes:

- PostgreSQL: Query pg_indexes for indexname, indexdef on each database - MySQL: Query information_schema.STATISTICS for INDEX_NAME, COLUMN_NAME, NON_UNIQUE - Flag missing, extra, or differently-defined indexes

  1. Compare constraints (primary keys, foreign keys, unique, check):

- Query information_schema.table_constraints and information_schema.key_column_usage - Detect missing foreign keys, changed constraint names, and altered check constraint expressions

  1. Compare functions, stored procedures, and triggers:

- PostgreSQL: Query pg_proc for function signatures and pg_trigger for trigger definitions - MySQL: Query information_schema.ROUTINES and information_schema.TRIGGERS - Compare function bodies for logical differences

  1. Compare enum types and custom types (PostgreSQL):

- Query pg_type and pg_enum for enum label differences - Detect added or removed enum values (note: PostgreSQL only supports adding enum values, not removing)

  1. Generate a structured diff report categorizing differences as:

- Added: Objects in source not present in target (require CREATE statements) - Removed: Objects in target not present in source (require DROP statements, confirm intentional) - Modified: Objects differing between source and target (require ALTER statements)

  1. Generate migration SQL to synchronize the target database to match the source:

- CREATE TABLE for new tables, ALTER TABLE ADD COLUMN for new columns - ALTER TABLE ALTER COLUMN for type changes, ALTER TABLE DROP COLUMN for removed columns - CREATE INDEX / DROP INDEX for index differences - Include transaction wrapping and rollback-safe operations

  1. Validate the generated migration by applying it to a copy of the target database and re-running the diff. The second diff should report zero differences, confirming the migration produces the expected state.

Output

  • Schema diff report listing all differences categorized by type (added, removed, modified)
  • Migration SQL script to synchronize target schema to match source
  • Rollback SQL script to reverse the migration if needed
  • Side-by-side comparison of differing object definitions
  • Drift detection summary highlighting changes not tracked in migration files

Error Handling

ErrorCauseSolution
Connection refused to one databaseNetwork or credential issue on source or targetVerify connection strings; check firewall rules; confirm credentials work with direct psql or mysql connection
Permission denied on pg_catalog queriesUser lacks read access to system catalogsGrant pg_read_all_settings role; or use pg_dump --schema-only which requires fewer privileges
False positive differences from default value formattingPostgreSQL normalizes default expressions differently in different versionsNormalize default value strings before comparison; ignore whitespace differences; compare semantic equivalence
Enum type modification blockedPostgreSQL does not support removing enum values or reorderingCreate a new enum type, migrate the column, drop the old type; document this as a multi-step migration
Generated migration fails on targetTarget has data that violates new constraintsAdd data validation queries before constraint creation; backfill default values; handle edge cases in migration

Examples

Detecting schema drift between staging and production: After 3 months without auditing, the diff reveals: 2 columns added to production manually (not in migrations), 1 index missing from staging, and 3 functions with different implementations. A migration script is generated to bring staging in sync, and the manual production changes are backported into migration files.

Pre-deployment schema validation: Before deploying a release with 5 migration files, run the diff between the post-migration staging schema and the expected schema. The diff catches a migration that accidentally dropped a constraint that a later migration depends on. The migration ordering is fixed before production deployment.

Comparing PostgreSQL schemas across major version upgrade: Schema extracted from PostgreSQL 14 and compared against PostgreSQL 16 after migration. Diff reveals function signature changes for built-in function calls, updated default values for new parameters, and deprecated syntax in stored procedures. Migration script updates function definitions for the new version.

Resources

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

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

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

平台分布

Codex

37.64%
按下载量换算79

Claude

29.36%
按下载量换算62

Cursor

19.23%
按下载量换算40

Gemini CLI

9.46%
按下载量换算20

安全审计

Gen Agent Trust Hub

可疑

Socket

通过

Snyk

通过

权限和风险

需要联网

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

安装前确认

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

来源信息

继续浏览同类 Skills