npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

migration-preflight

v0.2.1

Published

Test database migrations before you ship them: plant a row, run the migration, verify it survives.

Readme

🚀 migration-preflight



The problem

A migration can look fine and still destroy data: dropping and recreating a table, renaming a column, changing a type. None of that shows up against an empty local database. The same migration can silently wipe real rows the moment it runs against a database that actually has data in it, and by the time you find out, it already ran.

The idea

Plant a row before the migration, run it, and check the row is still there and still correct after. That's the difference between "it didn't crash" and "my data is safe."

flowchart LR
    M1[Migration 1] --> S["🌱 seed a row"] --> M2[Migration 2] --> M3[...] --> MN[Migration N]
    MN --> Check{Row still there?<br/>Foreign keys still valid?}
    Check -->|No| Bug[🔴 caught here, before it ships]
    Check -->|Yes| Safe[✅ safe to ship]

One test run replays your entire migration history and tells you exactly which step, if any, would have broken something.

Quick start

pnpm add -D migration-preflight @migration-preflight/sqlite
import { createNodeSqliteMigrationDatabase } from "@migration-preflight/sqlite"; // or -postgres
import { MigrationChain } from "migration-preflight";
import { drizzleFileSource } from "migration-preflight/sources"; // or prismaFileSource, sqlFileSource

const migrations = drizzleFileSource(join(import.meta.dirname, "out"));
const chain = new MigrationChain(createNodeSqliteMigrationDatabase(), migrations);

await chain.applyAll();

The payoff, catching a migration that silently drops data, comes from seeding a row between two migrations. See Seeding between migrations below.

📦 Packages

This package is the dialect-agnostic core: the replay engine and the ports it runs against. No database driver, no ORM dependency.

| Package | What it's for | | ----------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- | | migration-preflight | Core: replay engine, ports | | @migration-preflight/sqlite | SQLite driver (node:sqlite) | | @migration-preflight/postgres | Postgres driver (PGlite) |

migration-preflight isn't linked above: that's this package.

Seeding between migrations

A seed is a row tagged with the migration it goes in right after, a test fixture only, never imported by production code. applyAll runs it in place after that migration, so you can assert the row is still correct once every later migration has run:

import type { SqlStatement } from "migration-preflight";
import { renderInsert } from "migration-preflight";

const seedsByTag = new Map<string, readonly SqlStatement[]>([
  [
    "0000_create_users", // match your own first migration's tag
    [{ sql: renderInsert("users", { id: "u1", email: "[email protected]" }), params: [] }],
  ],
]);

await chain.applyAll((migration) => seedsByTag.get(migration.tag) ?? []);

// Still there after every later migration ran? Then this migration history is safe.
expect(await chain.hasRow("users", "u1")).toBe(true);
expect(await chain.foreignKeyViolations()).toEqual([]);

Seeding more rows is another seedsByTag entry, not a rewritten callback. See How-to § Seed a row between migrations for the full recipe, including a primary key column other than id.

Integrating with Drizzle, Prisma, plain SQL, and Postgres

migration-preflight itself only knows the MigrationSource, MigrationDatabase, and SqlDialect ports. Concrete support comes from two other packages, plus three bundled sources:

  • drizzleFileSource, prismaFileSource, sqlFileSource (all from migration-preflight/sources) each read a different migrations layout, Drizzle's journal, Prisma's migrations/ folder, or a flat folder of .sql files, into the Migration[] this package replays.
  • @migration-preflight/sqlite and @migration-preflight/postgres each supply a MigrationDatabase and, behind a /drizzle subpath, a thin wrapper over Drizzle's own migrator for a quick "does it apply cleanly" check.

📚 Documentation

Contributing

pnpm --filter migration-preflight test        # run the test suite
pnpm --filter migration-preflight typecheck   # type-check
pnpm --filter migration-preflight lint        # eslint

No database, no network, no setup, everything here runs in plain Node.

License

MIT