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

peta-migrate

v0.2.2

Published

Migration tools for peta-orm

Readme

peta-migrate

npm version TypeScript License

Standalone migration runner and generator for peta-orm. Run, roll back, and generate database migrations with a clean programmatic API and CLI.

bun add peta-migrate kysely @libsql/kysely-libsql @libsql/client

Requires kysely as a peer dependency. SQLite via @libsql/kysely-libsql, PostgreSQL via pg, MySQL via mysql2.


Quick Start

Programmatic

import { createClient } from "@libsql/client"
import { LibsqlDialect } from "@libsql/kysely-libsql"
import { Kysely } from "kysely"
import { createMigrationRunner, createMigrationGenerator } from "peta-migrate"

const db = new Kysely({ dialect: new LibsqlDialect({ url: "file:my-app.db" }) })
const runner = createMigrationRunner(db)

await runner.ensureTable()  // create tracking table

await runner.up([
  {
    name: "001_create_users",
    up: async (k) => {
      await k.schema
        .createTable("users")
        .addColumn("id", "integer", (c) => c.autoIncrement().primaryKey())
        .addColumn("name", "varchar(255)", (c) => c.notNull())
        .execute()
    },
    down: async (k) => {
      await k.schema.dropTable("users").execute()
    },
  },
])

// Check status
const completed = await runner.getCompleted()  // MigrationRecord[]
const status = await runner.status()           // { completed: [...], pending: [...] }

CLI

bun x peta migrate:init        # Create migrations directory and tracking table
bun x peta migrate:generate    # Generate initial migration from models
bun x peta migrate:up          # Run pending migrations
bun x peta migrate:status      # Show migration status

API

createMigrationRunner(kysely)

Creates a runner that manages migration execution.

| Method | Description | |--------|-------------| | ensureTable() | Create the migrations tracking table | | up(migrations) | Apply pending migrations in order | | down() | Roll back the last batch of migrations | | getCompleted() | Return list of completed migration records | | status() | Return { completed, pending } with both lists |

createMigrationGenerator()

Creates a generator that produces migration code from model definitions.

| Method | Description | |--------|-------------| | generateInitialMigration(models) | Generate a create-table migration from registered models |

Configuration

import { defineConfig } from "peta-migrate"

const config = defineConfig({
  migrationsDir: "./migrations",
  models: ["./src/models/*.ts"],
  getKysely: () => db,
})

| Option | Type | Description | |--------|------|-------------| | migrationsDir | string | Directory to store migration files | | models | string[] | string | Glob patterns for model files | | getKysely | () => Kysely | Function returning a Kysely instance |


Types

interface MigrationFile {
  name: string
  up: (db: Kysely<unknown>) => Promise<void>
  down: (db: Kysely<unknown>) => Promise<void>
}

interface MigrationRecord {
  name: string
  appliedAt: string
}

interface MigrationStatus {
  completed: MigrationRecord[]
  pending: MigrationFile[]
}

Related packages

  • peta-orm — ORM with models, relations, hooks, soft deletes
  • peta-auth — Encrypted cookie sessions, JWT, OAuth
  • peta-docs — OpenAPI 3.1 spec generation + Scalar UI