CO

comparing-database-schemas

Automates schema comparison and synchronization between different database environments.

Install

mkdir -p .claude/skills/comparing-database-schemas && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/4788" && unzip -o skill.zip -d .claude/skills/comparing-database-schemas && rm skill.zip

Installs to .claude/skills/comparing-database-schemas

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Process use when you need to work with schema comparison.
57 chars✓ has a “when” trigger
Advanced

Key capabilities

  • Extract database schema definitions
  • Compare tables, columns, and indexes
  • Detect schema drift across environments
  • Generate synchronization migration SQL
  • Validate migration safety

How it works

The skill extracts schema definitions using database-native tools like pg_dump or information_schema queries. It then compares these definitions to identify differences and generates SQL scripts to synchronize the target environment.

Inputs & outputs

You give it
Database connection strings and environment identifiers
You get back
Schema diff report and migration SQL script

When to use comparing-database-schemas

  • Compare dev vs staging schema
  • Sync database schemas between environments
  • Generate schema diff reports
  • Verify environment consistency

About this skill

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
  2. 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)
  3. 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)
  4. 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
  5. 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
  6. 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
  7. 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)
  8. 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)
  9. 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
  10. 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

When not to use it

  • Comparing actual table data content
  • Performing live database migrations without testing

Prerequisites

Connection credentials to source and target databasespsql or mysql CLI configuredRead access to information_schema

Limitations

  • PostgreSQL enum removal is not supported
  • Requires manual verification for complex constraint changes

How it compares

This process automates the identification of schema drift and generation of migration scripts, replacing manual inspection of database structures.

Compared to similar skills

comparing-database-schemas side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
comparing-database-schemas (this skill)127dReviewAdvanced
snowflake-semanticview56moReviewAdvanced
setup-timescaledb-hypertables04moNo flagsAdvanced
database-schema-design03moNo flagsIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

More by jeremylongshore

View all by jeremylongshore

analyzing-logs

jeremylongshore

Analyze application logs to detect performance issues, identify error patterns, and improve stability by extracting key insights.

14123

ollama-setup

jeremylongshore

Configure auto-configure Ollama when user needs local LLM deployment, free AI alternatives, or wants to eliminate hosted API costs. Trigger phrases: "install ollama", "local AI", "free LLM", "self-hosted AI", "replace OpenAI", "no API costs". Use when appropriate context detected. Trigger with relevant phrases based on skill purpose.

1167

backtesting-trading-strategies

jeremylongshore

Backtest crypto and traditional trading strategies against historical data. Calculates performance metrics (Sharpe, Sortino, max drawdown), generates equity curves, and optimizes strategy parameters. Use when user wants to test a trading strategy, validate signals, or compare approaches. Trigger with phrases like "backtest strategy", "test trading strategy", "historical performance", "simulate trades", "optimize parameters", or "validate signals".

1071

generating-database-seed-data

jeremylongshore

Process this skill enables AI assistant to generate realistic test data and database seed scripts for development and testing environments. it uses faker libraries to create realistic data, maintains relational integrity, and allows configurable data volumes. u... Use when working with databases or data models. Trigger with phrases like 'database', 'query', or 'schema'.

1033

cursor-codebase-indexing

jeremylongshore

Execute set up and optimize Cursor codebase indexing. Triggers on "cursor index setup", "codebase indexing", "index codebase", "cursor semantic search". Use when working with cursor codebase indexing functionality. Trigger with phrases like "cursor codebase indexing", "cursor indexing", "cursor".

885

testing-mobile-apps

jeremylongshore

Execute mobile app testing on iOS and Android devices/simulators. Use when performing specialized testing. Trigger with phrases like "test mobile app", "run iOS tests", or "validate Android functionality".

810

You might also like

snowflake-semanticview

github

Create, alter, and validate Snowflake semantic views using Snowflake CLI (snow). Use when asked to build or troubleshoot semantic views/semantic layer definitions with CREATE/ALTER SEMANTIC VIEW, to validate semantic-view DDL against Snowflake via CLI, or to guide Snowflake CLI installation and connection setup.

542

setup-timescaledb-hypertables

timescale

Use this skill when creating database schemas or tables for Timescale, TimescaleDB, TigerData, or Tiger Cloud, especially for time-series, IoT, metrics, events, or log data. Use this to improve the performance of any insert-heavy table. **Trigger when user asks to:** - Create or design SQL schemas/tables AND Timescale/TimescaleDB/TigerData/Tiger Cloud is available - Set up hypertables, compression, retention policies, or continuous aggregates - Configure partition columns, segment_by, order_by, or chunk intervals - Optimize time-series database performance or storage - Create tables for sensors, metrics, telemetry, events, or transaction logs **Keywords:** CREATE TABLE, hypertable, Timescale, TimescaleDB, time-series, IoT, metrics, sensor data, compression policy, continuous aggregates, columnstore, retention policy, chunk interval, segment_by, order_by Step-by-step instructions for hypertable creation, column selection, compression policies, retention, continuous aggregates, and indexes.

05

database-schema-design

RepairYourTech

Design database schemas with normalization, relationships, and constraints. Use when creating new database schemas, designing tables, or planning data models for any database paradigm.

00

Validate with Database

diegosouzapw

Connect to live PostgreSQL database to validate schema assumptions, compare pg_dump vs pgschema output, and query system catalogs interactively

00

drizzle-orm

EpicenterHQ

Drizzle ORM patterns for type branding and custom types. Use when working with Drizzle column definitions, branded types, or custom type conversions.

32190

database-design

davila7

Database design principles and decision-making. Schema design, indexing strategy, ORM selection, serverless databases.

648

Search skills

Search the agent skills registry