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

@shannonarcher/db-migrate-sql

v1.0.0

Published

Simple SQL migration tool with rollback support for PostgreSQL

Downloads

109

Readme

db-migrate-sql

Simple, lightweight SQL migration tool for PostgreSQL with rollback support. No ORM required - just plain SQL files.

Features

  • ✅ Pure SQL migrations (no ORM lock-in)
  • ✅ Rollback support with down.sql files
  • ✅ Database views management
  • ✅ Configurable paths and table names
  • ✅ Interactive prompts for safety
  • ✅ Migration status tracking
  • ✅ Timestamp-based naming

Installation

# Install in your project
npm install @shannonarcher/db-migrate-sql
# or
pnpm add @shannonarcher/db-migrate-sql

# Or install globally
npm install -g @shannonarcher/db-migrate-sql

Quick Start

# 1. Set your database URL
export DATABASE_URL="postgresql://user:password@localhost:5432/mydb"

# 2. Create a migration
npx db-migrate create add_users_table

# 3. Edit the generated SQL files
# - db/migrations/20240101120000_add_users_table/up.sql
# - db/migrations/20240101120000_add_users_table/down.sql

# 4. Run migrations
npx db-migrate up

# 5. View migration status
npx db-migrate list

Commands

create [name]

Create a new migration with up/down SQL files:

db-migrate create add_users_table

This creates:

db/migrations/20240101120000_add_users_table/
├── up.sql      # Apply migration
└── down.sql    # Rollback migration

up

Run all pending migrations:

db-migrate up

down [name]

Rollback a migration (prompts for confirmation):

# Rollback latest migration
db-migrate down

# Rollback specific migration
db-migrate down 20240101120000_add_users_table

list

Show applied and pending migrations:

db-migrate list

views

Apply all database views from db/views/*.sql:

db-migrate views

all

Run pending migrations AND apply views:

db-migrate all

config

Show current configuration:

db-migrate config

Configuration

Configure via environment variables:

# Required
DATABASE_URL=postgresql://user:password@localhost:5432/mydb

# Optional (with defaults)
MIGRATIONS_DIR=db/migrations          # Where migration folders live
VIEWS_DIR=db/views                     # Where view SQL files live
MIGRATIONS_TABLE=_migrations           # Table to track applied migrations

Migration Structure

Directory Layout

your-project/
├── db/
│   ├── migrations/
│   │   ├── 20240101120000_add_users_table/
│   │   │   ├── up.sql
│   │   │   └── down.sql
│   │   └── 20240102130000_add_posts_table/
│   │       ├── up.sql
│   │       └── down.sql
│   └── views/
│       ├── user_stats.sql
│       └── post_counts.sql
└── package.json

Example Migration

up.sql:

CREATE TABLE users (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  email VARCHAR(255) NOT NULL UNIQUE,
  name VARCHAR(255) NOT NULL,
  created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX idx_users_email ON users(email);

down.sql:

DROP INDEX IF EXISTS idx_users_email;
DROP TABLE IF EXISTS users;

Package.json Scripts

Add shortcuts to your package.json:

{
  "scripts": {
    "migrate": "db-migrate up",
    "migrate:down": "db-migrate down",
    "migrate:list": "db-migrate list",
    "migrate:create": "db-migrate create",
    "migrate:all": "db-migrate all"
  }
}

License

MIT

db-migrate-sql

db-migrate-sql