feat(db): Bun.SQL Kysely dialect for sqlite and postgres
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6c5a9fbad9
commit
8248a2ac27
11 files changed
+403
-1
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import type { Kysely } from "kysely";
|
||||
import { Migrator, type Migration, type MigrationProvider } from "kysely/migration";
|
||||
import type { Db } from "./db.ts";
|
||||
import { migrations } from "./migrations/index.ts";
|
||||
|
||||
class StaticMigrationProvider implements MigrationProvider {
|
||||
constructor(private readonly all: Record<string, Migration>) {}
|
||||
async getMigrations(): Promise<Record<string, Migration>> {
|
||||
return this.all;
|
||||
}
|
||||
}
|
||||
|
||||
/** Apply every pending migration; throws on the first failure. A no-op when there are none. */
|
||||
export async function migrateToLatest(db: Db): Promise<void> {
|
||||
const migrator = new Migrator({
|
||||
db: db.k as Kysely<any>,
|
||||
provider: new StaticMigrationProvider(migrations),
|
||||
});
|
||||
const { error, results } = await migrator.migrateToLatest();
|
||||
if (error) {
|
||||
const failed = results?.find((r) => r.status === "Error")?.migrationName;
|
||||
throw new Error(`Migration ${failed ?? "(unknown)"} failed: ${String(error)}`, { cause: error });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user