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

@hintergrund/d1-sync

v1.0.0

Published

Minimalistic auto-migration tool for Cloudflare D1 using raw SQL

Downloads

44

Readme

d1-sync

A minimalistic, zero-config (almost) auto-migration tool for Cloudflare D1.

Instead of managing ORM states or manually writing ALTER TABLE migrations, d1-sync treats your raw schema.sql as the single source of truth. It fetches the current schema from your production D1 database, compares it with your local schema.sql, generates the necessary SQLite ALTER TABLE or CREATE TABLE commands, and automatically applies them via wrangler d1.

Features

  • No ORM Required: Write pure SQL in your schema.sql.
  • Zero Configuration: Automatically infers database name from wrangler.toml or wrangler.json(c).
  • Reliable Diffing: Diffing happens against the actual live D1 database schema to prevent local drift.
  • Fast: Powered natively by sqlite3 CLI and Node.js.
  • Sequential Migrations: Generates ordered migration files (e.g., 0001_init.sql, 0002_add_users.sql).

Requirements

  • sqlite3 CLI installed on your system (pre-installed on macOS and most Linux distros).
  • A Cloudflare Workers project with Wrangler and D1 configured.

Installation

You can install it globally or add it as a dev dependency to your project:

npm install -D d1-sync

Usage

Simply make a change in your db/schema.sql (e.g., adding a column or table), and then run:

npx d1-sync --name "my_new_feature"

Options

Usage: d1-sync [options]

Options:
  -s, --schema <path>      Path to your schema.sql file (default: ./db/schema.sql)
  -m, --migrations <path>  Path to your migrations directory (default: ./migrations)
  -d, --db <name>          Database name (default: parses from wrangler.toml/jsonc)
  -n, --name <name>        Name of the migration (default: auto_migration)
      --dry-run            Print the generated SQL without applying or saving it
      --local-only         Only apply the migration to the local D1 database
      --remote-only        Only apply the migration to the remote D1 database
  -h, --help               Show this help message

How it works

  1. Fetch: Executes a query against your remote D1 database to get the current schema.
  2. Load: Loads your local schema.sql into an in-memory/temporary SQLite database.
  3. Compare: Checks for missing tables and columns.
  4. Generate: Creates a numbered .sql file in your ./migrations folder.
  5. Apply: Uses wrangler d1 execute to apply the migration locally and remotely.

Limitations

  • SQLite constraints: SQLite has limited ALTER TABLE support. d1-sync primarily supports creating new tables, creating new indexes, and adding new columns. Dropping or renaming columns requires table recreation, which is not currently automated to prevent accidental data loss.