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

@streetjs/migrations

v1.0.0

Published

StreetJS SQL migration runner and schema differ: ordered, idempotent, transactional migrations with a tracking table and rollback, plus a safe/destructive schema diff from entity metadata against the live database.

Readme

@streetjs/migrations

The StreetJS SQL migration runner and schema differ:

  • StreetMigrationRunner — applies ordered, idempotent, transactional .sql migrations from a directory, tracked in a street_migrations table, with rollback support and path-traversal-safe filename handling.
  • MigrationDiffer — compares your entity metadata against the live database schema (via @streetjs/schema-inspector) and reports safe (additive) vs. destructive DDL.

ESM, strict-TypeScript, @Injectable.

This is the standalone home of the migration tooling that also backs the streetjs framework. The framework re-exports this package, so there is a single source of truth.

Install

npm install @streetjs/migrations @streetjs/pool @streetjs/schema-inspector reflect-metadata

Running migrations

import { StreetMigrationRunner } from '@streetjs/migrations';

const runner = new StreetMigrationRunner(pool); // a PgPool

await runner.run('./migrations');      // apply all pending, in filename order
await runner.rollback('./migrations'); // roll back the most recent (needs *.rollback.sql)
  • Each migration runs in a transaction and is recorded in street_migrations; already-applied files are skipped.
  • Files are applied in lexicographic order — prefix them with a timestamp or zero-padded sequence (001_init.sql, 002_add_users.sql, …).
  • Filenames must match ^[A-Za-z0-9][A-Za-z0-9_\-.]*\.sql$; anything with path separators or .. is rejected.
  • A rollback for 001_init.sql looks for 001_init.rollback.sql.

Diffing entities against the database

import { MigrationDiffer } from '@streetjs/migrations';

const { safe, destructive } = await MigrationDiffer.diff(pool, [User, Post]);
// safe:        CREATE TABLE, ADD COLUMN (nullable/defaulted), CREATE INDEX
// destructive: DROP TABLE, DROP COLUMN, type changes, NOT NULL adds w/o default

The differ reads entity metadata from the street:* Reflect keys (street:table, street:columns, street:indexes, street:primaryKey) that the framework's @Entity/@Column decorators emit. Table names fall back to the lowercased class name. Framework-managed tables (street_*, sqlite_*) are never proposed for DROP. All identifiers, types, and defaults are validated to prevent SQL injection through metadata.

Safe vs. destructive

| Change | Bucket | | ------ | ------ | | Table missing | safeCREATE TABLE (+ its indexes) | | Nullable / defaulted column missing | safeADD COLUMN | | NOT NULL column missing (no default) | destructive — would fail on a populated table | | Column type change | destructiveALTER COLUMN … TYPE | | Column in DB, not in entity | destructiveDROP COLUMN | | Missing index | safeCREATE INDEX | | Live table with no entity | destructiveDROP TABLE (except framework tables) |

Example

A complete runnable example lives in src/examples/integration.ts:

npm run example -w packages/migrations

License

MIT — see LICENSE.