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 🙏

© 2025 – Pkg Stats / Ryan Hefner

digit-migrate

v1.0.8

Published

DigitCave is a lightweight migration and database ORM for SQL databases.

Readme

📖 DigitCave Migration Tool

DigitCave provides a simple and flexible migration runner for managing SQL database schemas across multiple services. This document explains the entry script used to run migrations.


🚀 Entry File: migrate.ts

#!/usr/bin/env ts-node

import dotenv from "dotenv";
dotenv.config();

import { authenticationDB, servicesDB } from "./config/db";
import { Schema } from "./config/migration/Schema";
import { Project } from "./entities/Project";
import { User } from "./entities/User";

export async function migrate() {
  Schema.init({
    dbConnections: {
      default: servicesDB,
      authentication: authenticationDB,
    },
    dialects: {
      default: "mysql",
      authentication: "mysql",
    },
    verbose: true,
    shouldLog: false,
    useBatch: true,
    shouldSyncAll: true,
    schemasWithFlags: [
      { fn: () => User.sync(), shouldSync: true },
      { fn: () => Project.sync(), shouldSync: true },
    ],
  });

  console.log("🚀 Starting schema migrations...");
  await Schema.syncMarkedSchemas();
  console.log("🎉 Migrations finished.");
}

migrate().catch((err) => {
  console.error("❌ Migration failed:", err);
  process.exit(1);
});

⚙️ How it Works

  1. Environment Setup Loads database credentials from .env file using dotenv.

  2. Database Connections Two connections are configured:

    • servicesDB → The default database
    • authenticationDB → The authentication database
  3. Schema Initialization The Schema.init() method configures:

    • Supported connections & dialects
    • Logging preferences (verbose, shouldLog)
    • Migration behavior (useBatch, shouldSyncAll)
    • List of entities/models to sync (schemasWithFlags)
  4. Migration Execution

    • Schema.syncMarkedSchemas() runs all models flagged with shouldSync: true.
    • Logs start & finish messages to console.
    • Exits gracefully on error.

📦 Usage

Run Migrations

ts-node migrate.ts

Or, if installed globally / via npx:

digitcave migrate

Example .env file

DB_HOST=localhost
DB_USER=root
DB_PASSWORD=secret
DB_NAME=services
AUTH_DB_NAME=auth

Expected Console Output

🚀 Starting schema migrations...
🎉 Migrations finished.

If something fails:

❌ Migration failed: Error: Connection refused

🏗️ Adding a New Entity

  1. Define your entity in ./entities:
export class Product {
  static async sync() {
    console.log("🔄 Syncing Product schema...");
    // schema logic here
  }
}
  1. Register it in migrate.ts:
schemasWithFlags: [
  { fn: () => User.sync(), shouldSync: true },
  { fn: () => Project.sync(), shouldSync: true },
  { fn: () => Product.sync(), shouldSync: true },
],
  1. Run migration again:
ts-node migrate.ts

🔑 CLI Alias (Optional)

Add a bin entry in package.json to run as a global tool:

"bin": {
  "digitcave": "./migrate.ts"
}

Then:

npm install -g .
digitcave migrate