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

@stanstack/pg-migrate

v0.0.2

Published

A simple, scriptable PostgreSQL migration and schema management toolkit for Node.js/TypeScript projects. This package provides CLI tools to initialize your database directory, manage migrations, and generate type-safe database code using [apgdiff](https:/

Readme

@stanstack/pg-migrate

A simple, scriptable PostgreSQL migration and schema management toolkit for Node.js/TypeScript projects. This package provides CLI tools to initialize your database directory, manage migrations, and generate type-safe database code using apgdiff, pgvector, Kysely and Kanel.


Concept

The schema.sql file is the canonical source of truth for your database schema. You cannot tear down your production database and create it again every time you make a change to the schema. Instead, pg-migrate works out the diff between the schema.sql file and the current state of your database, and saves that diff as a migration file in the migrations directory (which can be edited manually if needed). The migrations are then applied to your database.

This way you get both control over what's getting applied to your production database, and the speed and clarity of the thing that you're editing being the source of truth - just like any other code.


Why these technologies?

apgdiff

apgdiff is a currently (as of 2025-06-24) maintained diff tool that is easy to use via docker. It's got broad support for PostgreSQL features.

pgvector

pgvector is the vector database extension for PostgreSQL. A lot of modern applications have needs for vector data, and pgvector is a good choice for that.

Kysely

Kysely is a SQL query builder for TypeScript/JavaScript. It is a good choice for database access in a Node.js/TypeScript project: giving you the full power of SQL while maintaining type safety.

Kanel

Kanel is a SQL to TypeScript generator that integrates well with Kysely.


Getting Started

1. Install the Package

Add @stanstack/pg-migrate to your project:

npm install --save-dev @stanstack/pg-migrate

or with your preferred package manager:

pnpm add -D @stanstack/pg-migrate

2. Initialize Your Database Directory

Run the init script to set up your database directory. You can specify a custom path or accept the default (./db).

npx @stanstack/pg-migrate init
# or, with a custom directory
npx @stanstack/pg-migrate init ./my-db-dir

This will create the specified directory (if it doesn't exist) with all the necessary files and directories for your database.

3. Configure Environment Variables

Use the following environment variables for any commands you run:

DATABASE_URL=postgres://user:password@host:port/database
DB_DIR=./db  # Or your chosen database directory

4. Make a Change

Edit schema.sql to make your desired changes to the schema.

5. Generate a Migration

Run the generate script to generate a migration file based on the diff between schema.sql and your current database state:

npx @stanstack/pg-migrate generate "description"

6. [Optional] Edit the Migration

If you need to make changes to the generated migration, you can edit the file in the migrations directory.

7. Apply the Migration

Run the migrate script to apply the migration to your database:

npx @stanstack/pg-migrate migrate

8. Develop your Application

Use the types generated in types with Kysely to develop your application with type safety. Repeat steps 4-7 as you develop the application.


Freebies

A docker-compose.yml file is provided for convenience. It sets up a PostgreSQL database with the necessary environment variables.


Requirements

  • Node.js 18+
  • Docker (this is required for diffing the schema)

License

MIT