
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
pg-schema-compare
Advanced tools
Compare two PostgreSQL database schemas structurally, ignoring naming differences
Structurally compare two PostgreSQL database schemas, ignoring constraint and index naming differences.
Useful for verifying that a fresh migration produces the same schema as an existing database.
Most schema diff tools (e.g. migra, pgquarrel, pg-schema-diff) focus on generating migration SQL to bring one schema in line with another. This tool takes a different approach:
0 = identical, 1 = differences, 2 = error) make it easy to integrate into CI pipelines for migration drift detection.Ideal for teams that want to answer one question: "Does running migrations from scratch produce the exact same schema as our existing database?"
bun add -g pg-schema-compare
Or run directly with bunx:
bunx pg-schema-compare \
--from postgres://user:pass@host:5432/db1 \
--to postgres://user:pass@host:5432/db2
# Compare two databases
pg-schema-compare \
--from postgres://user:pass@host:5432/db_existing \
--to postgres://user:pass@host:5432/db_fresh
# Exclude specific tables
pg-schema-compare \
--from postgres://user:pass@host:5432/db1 \
--to postgres://user:pass@host:5432/db2 \
--exclude migrations,logs
A full PostgreSQL connection string is required. Plain database names are not supported.
| Option | Required | Description |
|---|---|---|
--from | Yes | Source database connection string |
--to | Yes | Target database connection string |
--exclude | No | Comma-separated list of tables to exclude from comparison |
| Category | Details |
|---|---|
| Tables | Detects entire tables that exist in one database but not the other |
| Columns | Data type, nullability, default value (with sequence and type cast normalization) |
| Indexes | Normalized index definitions (index names are ignored) |
| Foreign Keys | Foreign key constraint definitions (constraint names are ignored) |
| Check Constraints | CHECK constraint definitions (NOT NULL checks are excluded) |
| Unique Constraints | UNIQUE constraint definitions (constraint names are ignored) |
| Enum Types | Custom PostgreSQL enum types and their values |
| Extensions | Installed PostgreSQL extensions and their versions |
The following normalizations are applied during comparison to avoid false positives:
nextval('any_seq_name'::regclass) -> nextval(autoincrement)'0'::bigint -> 0, NULL::character varying -> NULLCREATE INDEX idx_name ON ... -> CREATE INDEX ON ...CHECK ((col IS NOT NULL)) constraints are filtered outWhen an entire table is missing from one database, it is reported as a single table-level diff instead of listing every column individually. Column-level diffs are only shown for tables that exist in both databases.
| Code | Meaning |
|---|---|
0 | Schemas are identical |
1 | Differences found |
2 | Connection or runtime error |
import { fetchSchema, compareSchemas, formatDiffText } from 'pg-schema-compare'
const source = await fetchSchema('postgres://user:pass@localhost:5432/db1')
const target = await fetchSchema('postgres://user:pass@localhost:5432/db2')
const diff = compareSchemas(source, target)
// diff.tables -> TableDiff[]
// diff.columns -> ColumnDiff[]
// diff.indexes -> IndexDiff[]
// diff.foreignKeys -> ForeignKeyDiff[]
// diff.checkConstraints -> CheckConstraintDiff[]
// diff.uniqueConstraints -> UniqueConstraintDiff[]
// diff.enumTypes -> EnumTypeDiff[]
// diff.extensions -> ExtensionDiff[]
// Format as CLI output
const output = formatDiffText({
diff,
sourceName: 'db1',
targetName: 'db2',
source,
target,
})
# Install dependencies
bun install
# Run tests (requires PostgreSQL)
cp .env.test.example .env.test # adjust PG_URL if needed
bun test
# Lint, format, type check
bun run check
# Auto-fix lint and format issues
bun run fix
FAQs
Compare two PostgreSQL database schemas structurally, ignoring naming differences
We found that pg-schema-compare demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.