rwsdk
Version:
Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime
35 lines (34 loc) • 1.02 kB
JavaScript
import { Migrator } from "kysely";
/**
* A custom MigrationProvider that works with in-memory migrations
* rather than reading from files.
*/
export class InMemoryMigrationProvider {
constructor(migrations) {
this.migrations = migrations;
}
async getMigrations() {
return this.migrations;
}
}
/**
* Helper function to create a migrator using Kysely's built-in Migrator.
*
* @example
* ```typescript
* const migrator = createMigrator(db, migrations, "__my_migrations");
* const result = await migrator.migrateToLatest();
* if (result.error) {
* throw new Error(`Migration failed: ${result.error}`);
* }
* ```
*/
export function createMigrator(db, migrations, migrationTableName = "__rwsdk_migrations") {
return new Migrator({
db,
provider: new InMemoryMigrationProvider(migrations),
migrationTableName,
// Use a custom lock table name based on the migration table name
migrationLockTableName: `${migrationTableName}_lock`,
});
}