simple-kiosk-app/migrate.ts

54 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2024-04-20 19:58:18 +09:00
import * as path from 'path'
import { promises as fs } from 'fs'
import {
Kysely,
Migrator,
SqliteDialect,
FileMigrationProvider,
} from 'kysely'
import SQLite from "better-sqlite3";
import { Database } from './lib/types';
export async function migrateToLatest() {
const __dirname = path.resolve();
const db = new Kysely<Database>({
dialect: new SqliteDialect({
database: new SQLite("order.sqlite3"),
}),
})
const { up } = await import('./migration/2024-04-19');
await up(db);
// const migrator = new Migrator({
// db,
// provider: new FileMigrationProvider({
// fs,
// path,
// // This needs to be an absolute path.
// migrationFolder: path.join(__dirname, './migration'),
// }),
// })
// const { error, results } = await migrator.migrateToLatest()
// results?.forEach((it) => {
// if (it.status === 'Success') {
// console.log(`migration "${it.migrationName}" was executed successfully`)
// } else if (it.status === 'Error') {
// console.error(`failed to execute migration "${it.migrationName}"`)
// }
// })
// if (error) {
// console.error('failed to migrate')
// console.error(error)
// process.exit(1)
// }
await db.destroy()
}
migrateToLatest()