diff --git a/src/db/migrations.ts b/src/db/migrations.ts index 412b6c6..bc4d7cd 100644 --- a/src/db/migrations.ts +++ b/src/db/migrations.ts @@ -1,52 +1,52 @@ -import { promises as fs } from "fs"; +import { promises as fs } from 'fs' import { FileMigrationProvider, Kysely, Migrator, - PostgresDialect, -} from "kysely"; -import * as path from "path"; -import { Pool } from "pg"; -import Database from "./model"; + PostgresDialect +} from 'kysely' +import * as path from 'path' +import { Pool } from 'pg' +import type Database from './model' -async function migrateToLatest() { +async function migrateToLatest () { const db = new Kysely({ dialect: new PostgresDialect({ pool: new Pool({ host: process.env.POSTGRES_HOST, database: process.env.POSTGRES_DATABASE, user: process.env.POSTGRES_USER, - password: process.env.POSTGRES_PASSWORD, - }), - }), - }); + password: process.env.POSTGRES_PASSWORD + }) + }) + }) const migrator = new Migrator({ db, provider: new FileMigrationProvider({ fs, path, - migrationFolder: path.join(__dirname, "./migrations"), - }), - }); + migrationFolder: path.join(__dirname, './migrations') + }) + }) - const { error, results } = await migrator.migrateToLatest(); + 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 (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); + console.error('failed to migrate') + console.error(error) + process.exit(1) } - await db.destroy(); + await db.destroy() } -export default migrateToLatest; +export default migrateToLatest