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

@anchan828/kysely-migration

v0.9.25

Published

Migration helper package for Kysely

Readme

@anchan828/kysely-migration

npm NPM

Migration library for kysely.

Installation

$ npm i --save kysely @anchan828/kysely-migration

Quick Start

KyselyMigrationClassProvider

This provider can perform migration by passing the Migration class.

import { Kysely, Migration } from "kysely";
import { KyselyMigrationClassProvider } from "@anchan828/kysely-migration";

class CreateUserTable implements Migration {
  public async up(db: Kysely<any>): Promise<void> {
    await db.schema
      .createTable("user")
      .addColumn("id", "integer", (cb) => cb.primaryKey().autoIncrement().notNull())
      .addColumn("name", "varchar(255)", (cb) => cb.notNull())
      .execute();
  }
}

const provider = new KyselyMigrationClassProvider([CreateUserTable]);

await new Migrator({ db, provider }).migrateToLatest();

KyselyMigrationFileProvider

This provider can perform migration by passing the migrations directory path. This provider wraps the FileMigrationProvider provided by kysely and supports SQL files.

migrations
├── 1715003546247-CreateUserTable.ts
├── 1715003558664-CreateUserInsertTrigger.sql
├── 1715003568628-UpdateUserTable.sql
└── 1715003583015-CreateUserTableIndex.js
const provider = new KyselyMigrationFileProvider({
  fs: require("fs"),
  path: require("path"),
  migrationFolder: path.join(__dirname, "migrations"),
});

await new Migrator({ db, provider }).migrateToLatest();

KyselyMigrationMergeProvider

This provider can perform migration by merging multiple providers.

const provider = new KyselyMigrationMergeProvider({
  providers: [
    new KyselyMigrationFileProvider({
      fs: require("fs"),
      path: require("path"),
      migrationFolder: path.join(__dirname, "migrations"),
    }),
    new KyselyMigrationClassProvider([CreateUserTable]),
  ],
});

await new Migrator({ db, provider }).migrateToLatest();

Repeatable Migrations

This is a feature to support migrations that need to be regenerated multiple times, such as views/functions/triggers/etc. Unlike migrations that are executed only once, it compares the checksum of the SQL to be executed to determine the need for migration.

import { KyselyRepeatableMigrationSqlFileProvider, RepeatableMigrator } from "@anchan828/kysely-migration";
const provider = new KyselyRepeatableMigrationSqlFileProvider({
  sqlFiles: [resolve(__dirname, "user-view.sql")],
  sqlTexts: [{ name: "test", sql: "SELECT 1;" }],
});

await new RepeatableMigrator({ db, provider }).migrateToLatest();

| name | hash | timestamp | | --------- | -------------------------------- | ------------------------ | | user-view | 6c7e36422f79696602e19079534b4076 | 2024-05-11T17:04:20.211Z | | test | e7d6c7d4d9b1b0b4c7f5d7b3d5e9d4d4 | 2024-05-11T17:04:20.211Z |

Note

  • Once the file is renamed, the migration is executed even if the contents have not changed.
  • Views/Functions/Triggers created by Repeatable Migration are not automatically deleted (or update/rename) by simply deleting the corresponding SQL, so please delete them using the normal migration function.

License

MIT