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

drizzle-pgkit-migrator

v0.1.1

Published

CLI glue for managing a Drizzle schema with @pgkit/migrator and @pgkit/migra: generate schema.sql, diff to create migrations, run pgkit migrations.

Readme

drizzle-pgkit-migrator

test codecov npm

CLI glue between drizzle-kit and @pgkit/migrator / @pgkit/migra.

Motivation

Drizzle is a great way to author a Postgres schema in TypeScript, but drizzle-kit's migration workflow leans on a journal (_journal.json plus per-migration snapshot files) to know what changed. The journal is fragile: it's easy to corrupt during rebases, hard to reason about across long-lived branches, and ties every migration to drizzle-kit's internal snapshot format rather than to the actual database state.

This package lets the Drizzle schema be the single source of truth for what the database should look like, with no migration journal. The flow:

  1. Author tables in Drizzle as usual.
  2. generate-schema produces a plain schema.sql describing the desired state directly from the Drizzle schema (plus any raw-SQL snippets for things Drizzle can't express — extensions, triggers, custom functions).
  3. create diffs schema.sql against the result of replaying your existing .sql migrations into a throwaway database, using @pgkit/migra. The output is a normal SQL migration file — no snapshot, no journal.
  4. migrate runs those plain SQL files against your real database with @pgkit/migrator, which tracks applied migrations in a regular table.

The result: migrations are just SQL files, the schema is just Drizzle, and the only state that matters is what's actually in the database.

It lets you keep authoring your schema in Drizzle while running migrations with pgkit:

  1. generate-schema — turns your Drizzle schema (plus optional raw-SQL snippets) into a single schema.sql describing the desired state.
  2. create — spins up two throwaway databases (one from schema.sql, one from your existing migrations) and uses @pgkit/migra to write a new migration containing the diff.
  3. migrate up|down|list|pending|executed — runs @pgkit/migrator against your real database. Subcommands and flags are forwarded to pgkit's own CLI.
  4. backfill — for repos switching off drizzle-kit migrations: copies the existing drizzle.__drizzle_migrations history into the pgkit migrations table so they're treated as already applied.

Install

npm install --save-dev drizzle-pgkit-migrator drizzle-kit

CLI

npx drizzle-pgkit-migrator <command> [options]

All commands accept --database-url (or read DATABASE_URL from the environment).

generate-schema

npx drizzle-pgkit-migrator generate-schema \
  --schema-dir src/db/schema \
  --schema-file src/db/__generated__/schema.sql

Runs drizzle-kit generate into a temp dir, then weaves in any pgCustomSQL snippets exported from your schema files (sorted by priority — negative goes before tables, positive goes after).

create

npx drizzle-pgkit-migrator create \
  --schema-file src/db/__generated__/schema.sql \
  --migrations-dir src/db/migrations \
  --name add_users_table

Use --exit-code instead of --name to fail CI when there's drift but write nothing. --allow-empty writes an empty file when the diff is clean.

migrate

npx drizzle-pgkit-migrator migrate --migrations-dir src/db/migrations up
npx drizzle-pgkit-migrator migrate --migrations-dir src/db/migrations list
npx drizzle-pgkit-migrator migrate --migrations-dir src/db/migrations pending
npx drizzle-pgkit-migrator migrate --migrations-dir src/db/migrations executed

backfill

npx drizzle-pgkit-migrator backfill --migrations-dir src/db/migrations

Marks every .sql file in --migrations-dir as already applied, copying the timestamps from drizzle.__drizzle_migrations.

Programmatic API

Every command also has a typed function export:

import {
  generateSchemaSql,
  createMigration,
  createMigrator,
  backfillMigrations,
  pgCustomSQL,
} from "drizzle-pgkit-migrator";

pgCustomSQL

Use this in your Drizzle schema to inject raw SQL into the generated schema.sql:

import { sql } from "drizzle-orm";
import { pgCustomSQL } from "drizzle-pgkit-migrator";

export const fuzzystrmatch = pgCustomSQL(
  sql`CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;`,
  { priority: -10 },
);

export const myTrigger = pgCustomSQL(
  sql`
    CREATE TRIGGER "MyTable_trigger"
    AFTER INSERT ON public."MyTable" FOR EACH ROW
    EXECUTE FUNCTION public.my_fn('id');
  `,
  { priority: 1 },
);

The Drizzle migration sits at priority 0. Negative priorities are placed before the table definitions, non-negative after.