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

@netkasystem/drizzle-db-patch

v0.1.3

Published

Generate SQL patches by diffing Drizzle schema against a live PostgreSQL database, plus a seed dry-runner that captures INSERT statements without touching the DB.

Downloads

26

Readme

@netka-entrust/drizzle-db-patch

Generate SQL patches for PostgreSQL databases backed by Drizzle ORM:

  • generate — diff a Drizzle schema module against a live database and emit a SQL patch (CREATE TABLE, ADD COLUMN, CREATE INDEX, ADD FOREIGN KEY, ADD UNIQUE, plus commented DROPs for orphans). Read-only against the target DB.
  • seed — dry-run a seed orchestrator and capture every emitted INSERT as inline SQL. The DB client is stubbed; no real connection is opened.

Peer-depends on drizzle-orm (>= 0.30) and postgres (>= 3.4). Node ≥ 20.

Install

pnpm add -D @netkasystem/drizzle-db-patch

Published as a public package on npmjs.com — no authentication required.

CLI

generate — schema vs live DB

DATABASE_URL="postgres://user:pass@host:5432/db" \
  pnpm drizzle-db-patch generate \
    --schema ./src/db/schema \
    --out ./scripts/db-patch.sql

Options:

| Flag | Default | Description | | ---------------- | --------------- | ----------------------------------------------------------------------------------------------------------- | | --schema | (required) | Path to a module that exports the Drizzle schema (typically a barrel file that re-exports every pgTable). | | --database-url | $DATABASE_URL | Postgres connection URL. Read-only access is sufficient. | | --out | db-patch.sql | Output file. |

Output sections (each wrapped in BEGIN/COMMIT):

  1. Missing tables — CREATE TABLE IF NOT EXISTS
  2. Missing columns — ALTER TABLE ADD COLUMN IF NOT EXISTS
  3. Orphan tables — commented DROP TABLE (manual review)
  4. Orphan columns — commented ALTER TABLE DROP COLUMN (manual review)
  5. Missing indexes — CREATE INDEX IF NOT EXISTS
  6. Missing foreign keys — ALTER TABLE ADD CONSTRAINT ... FOREIGN KEY
  7. Missing unique constraints — ALTER TABLE ADD CONSTRAINT ... UNIQUE

seed — dry-run a seed orchestrator

The seed command needs an entrypoint module that wires your application's DB client to the stub provided by this package. Create a file like scripts/seed-patch-entry.ts:

import type { GenerateSeedPatchOptions } from "@netkasystem/drizzle-db-patch";

const opts: GenerateSeedPatchOptions = {
  installStub: async (stub) => {
    // Replace the real postgres-js client with the stub. The exact wiring
    // depends on how your app exposes the client.
    const dbModule = (await import("@/db")) as {
      db: { session: { client: unknown } };
    };
    dbModule.db.session.client = stub;
  },
  runSeed: async () => {
    // Intercept process.exit so the seed runner doesn't kill our process
    // before we write the patch.
    const origExit = process.exit.bind(process);
    let exited = false;
    (process as unknown as { exit: (code?: number) => void }).exit = (() => {
      exited = true;
    }) as never;
    try {
      await import("@/db/seed/seed");
      const start = Date.now();
      while (!exited) {
        if (Date.now() - start > 300_000) {
          throw new Error("Timed out waiting for seed to finish (5 min).");
        }
        await new Promise((r) => setTimeout(r, 100));
      }
    } finally {
      process.exit = origExit;
    }
  },
  header: ["Source: src/db/seed (dry-run, no DB connection)"],
};

export default opts;

Then run:

pnpm drizzle-db-patch seed \
  --entry ./scripts/seed-patch-entry.ts \
  --out ./scripts/seed-patch.sql

The CLI loads the entry module, calls installStub(stub), runs runSeed(), and writes captured INSERTs to --out. SELECTs are answered from rows inserted earlier in the same run (best-effort), so seeds that chain INSERT ... RETURNING -> SELECT can usually complete.

Programmatic API

import {
  generateDbPatch,
  generateSeedPatch,
} from "@netkasystem/drizzle-db-patch";
import * as schema from "./src/db/schema";

const { sql, stats } = await generateDbPatch({
  schema,
  databaseUrl: process.env.DATABASE_URL!,
});

See src/index.ts for full type definitions.

Publishing (manual)

The package is not auto-published. Bump the version and publish from a local workstation:

cd packages/drizzle-db-patch

# 1. Bump version
npm version patch  # or minor / major

# 2. Build
pnpm build

# 3. Login to npmjs.com (once per machine)
npm login

# 4. Publish
npm publish --registry=https://registry.npmjs.org

The package's publishConfig.registry points at https://registry.npmjs.org. The --registry flag overrides any scope mapping in your global ~/.npmrc (e.g. if @netkasystem is mapped to GitHub Packages there).

After publishing, commit the version bump:

git add packages/drizzle-db-patch/package.json
git commit -m "chore(drizzle-db-patch): publish vX.Y.Z"