comparing-database-schemas

0
1
Source

Process use when you need to work with schema comparison. This skill provides database schema diff and sync with comprehensive guidance and automation. Trigger with phrases like "compare schemas", "diff databases", or "sync database schemas".

Install

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

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

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

svg-icon-generator

jeremylongshore

Svg Icon Generator - Auto-activating skill for Visual Content. Triggers on: svg icon generator, svg icon generator Part of the Visual Content skill category.

10735

d2-diagram-creator

jeremylongshore

D2 Diagram Creator - Auto-activating skill for Visual Content. Triggers on: d2 diagram creator, d2 diagram creator Part of the Visual Content skill category.

8833

automating-mobile-app-testing

jeremylongshore

This skill enables automated testing of mobile applications on iOS and Android platforms using frameworks like Appium, Detox, XCUITest, and Espresso. It generates end-to-end tests, sets up page object models, and handles platform-specific elements. Use this skill when the user requests mobile app testing, test automation for iOS or Android, or needs assistance with setting up device farms and simulators. The skill is triggered by terms like "mobile testing", "appium", "detox", "xcuitest", "espresso", "android test", "ios test".

18728

performing-penetration-testing

jeremylongshore

This skill enables automated penetration testing of web applications. It uses the penetration-tester plugin to identify vulnerabilities, including OWASP Top 10 threats, and suggests exploitation techniques. Use this skill when the user requests a "penetration test", "pentest", "vulnerability assessment", or asks to "exploit" a web application. It provides comprehensive reporting on identified security flaws.

5519

designing-database-schemas

jeremylongshore

Design and visualize efficient database schemas, normalize data, map relationships, and generate ERD diagrams and SQL statements.

12516

optimizing-sql-queries

jeremylongshore

This skill analyzes and optimizes SQL queries for improved performance. It identifies potential bottlenecks, suggests optimal indexes, and proposes query rewrites. Use this when the user mentions "optimize SQL query", "improve SQL performance", "SQL query optimization", "slow SQL query", or asks for help with "SQL indexing". The skill helps enhance database efficiency by analyzing query structure, recommending indexes, and reviewing execution plans.

5513

You might also like

flutter-development

aj-geddes

Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.

1,6771,424

ui-ux-pro-max

nextlevelbuilder

"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."

1,2541,315

drawio-diagrams-enhanced

jgtolentino

Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.

1,5241,142

godot

bfollington

This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.

1,346805

nano-banana-pro

garg-aayush

Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.

1,260725

pdf-to-markdown

aliceisjustplaying

Convert entire PDF documents to clean, structured Markdown for full context loading. Use this skill when the user wants to extract ALL text from a PDF into context (not grep/search), when discussing or analyzing PDF content in full, when the user mentions "load the whole PDF", "bring the PDF into context", "read the entire PDF", or when partial extraction/grepping would miss important context. This is the preferred method for PDF text extraction over page-by-page or grep approaches.

1,465673