How to Diff Database Schemas Between Git Branches
One of the most common questions we hear from engineering teams is: "How do I know what changed in my database schema between the branch I'm reviewing and production?"
Until recently, the answer involved a lot of manual work: clone the repo, check out both branches, export schemas, open them side by side, and squint at the differences. That friction meant schema reviews were often skipped — and breaking changes slipped into production.
Today, you can compare schema files between any two Git branches, tags, or commits directly in your browser, without cloning anything. Here's how.
🌿 Try it now
Compare schema files between Git branches instantly. No clone, no install, no signup.
Open Git Branch Schema Diff →The Problem: Schema Reviews Are Invisible
Code reviews are standard practice. Every PR gets line-by-line scrutiny. But schema changes? They often get a cursory glance at best. The problem is tooling:
- ORM migrations hide the real schema. Reviewing a Rails
db/migratefile or a Prisma migration tells you what the developer intended, not the actual end state. - Schema dumps are huge. A
pg_dumpormysqldumpoutput for a 50-table schema is thousands of lines. No one wants to read that in a PR diff. - Context switching kills focus. To verify a schema change, you leave the PR, open your database tool, export both schemas, and compare them manually. Most reviewers skip this step.
The result: dropped columns, missing indexes, and type changes that break production — all approved because the reviewer never saw the actual schema diff.
The Solution: Browser-Based Branch Comparison
SchemaLens now supports comparing schema files between any two Git refs from public GitHub repositories. Here's what that means in practice:
- Paste a GitHub repo URL (e.g.,
rails/rails) - Enter the schema file path (e.g.,
db/schema.rborschema.sql) - Pick a base branch/tag/commit (e.g.,
main) - Pick a head branch/tag/commit (e.g.,
feature/user-roles) - Click Compare and see the semantic diff instantly
The tool fetches both files directly from GitHub's raw content CDN, parses them with SchemaLens's custom SQL parser, and shows you a visual diff: tables added or removed, columns changed, indexes modified, constraints updated. It also generates the migration script to get from base to head.
Real-World Example: Reviewing a Feature Branch
Imagine your team is reviewing a PR that adds a role column to the users table and creates a new permissions table. The PR includes the migration files, but you want to verify the end-state schema is correct.
Instead of checking out the branch locally, you open the Git Branch Schema Diff tool and enter:
Repo: your-org/your-app File: db/schema.sql Base: main Head: feature/user-permissions
Within seconds, you see:
- ✅
users.roleadded asVARCHAR(50) NOT NULL DEFAULT 'user' - ✅ New table
permissionswith correct foreign key tousers.id - ⚠️
users.emaillost itsUNIQUEconstraint — potential breaking change
You leave a PR comment about the missing unique constraint, the author fixes it, and a production incident is prevented.
When to Use Branch Diff vs. CI/CD Integration
SchemaLens offers two complementary workflows for catching schema changes:
| Workflow | Best For | Trigger |
|---|---|---|
| Browser Branch Diff | Ad-hoc reviews, open source analysis, debugging | Manual — whenever you need it |
| GitHub Action | Automated checks on every PR, team enforcement | Automatic — runs in CI on every push |
For individual developers and occasional reviews, the browser tool is perfect. For teams that want to enforce schema review on every PR, the GitHub Action posts diff summaries directly as PR comments and can fail the build on breaking changes.
Supported Repos and File Formats
The browser-based branch diff works with any public GitHub repository. It auto-detects the SQL dialect from the file content, so you can compare:
- Raw SQL dumps (
schema.sql,dump.sql) - Rails schema files (
db/schema.rb— partial support for Ruby DSL) - Django migration summaries
- Any file containing
CREATE TABLEstatements
Both the base and head can be any valid Git reference: branch names, tags (e.g., v2.1.0), or full 40-character commit SHAs.
Try It on Real Projects
The tool includes presets for well-known open source projects so you can see how it works immediately:
- Rails: Compare
db/schema.rbbetween7-0-stableandmain - Django: Compare
django/db/backends/postgresql/schema.pybetween releases - WordPress: Compare
wp-admin/includes/schema.phpbetween versions - Supabase: Compare
supabase/migrationsfiles between branches
These presets are not just demos — they're useful for understanding how mature projects evolve their schemas over time.
From Diff to Migration
Seeing the diff is only half the value. Once SchemaLens identifies the changes, it can generate the migration script in your chosen dialect:
-- PostgreSQL ALTER TABLE users ADD COLUMN role VARCHAR(50) NOT NULL DEFAULT 'user'; CREATE TABLE permissions ( id SERIAL PRIMARY KEY, user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE, resource VARCHAR(100) NOT NULL, action VARCHAR(50) NOT NULL ); CREATE INDEX idx_permissions_user_id ON permissions(user_id);
Copy, paste into your migration framework, and deploy. The entire workflow — from "I wonder what changed" to "here's the migration" — takes under a minute.
Privacy and Security
Because SchemaLens runs entirely in your browser, the schema files are fetched from GitHub's CDN directly to your machine. They never pass through SchemaLens servers. For public repositories, this means zero authentication and zero data retention.
For private repositories, use the GitHub Action inside your own CI environment, or download the schema files and use the main SchemaLens app offline.
Start comparing schemas between branches
Free. No signup. No clone required.
Open Git Branch Diff → Add GitHub Action →