eslint format
This commit is contained in:
+25
-25
@@ -1,52 +1,52 @@
|
|||||||
import { promises as fs } from "fs";
|
import { promises as fs } from 'fs'
|
||||||
import {
|
import {
|
||||||
FileMigrationProvider,
|
FileMigrationProvider,
|
||||||
Kysely,
|
Kysely,
|
||||||
Migrator,
|
Migrator,
|
||||||
PostgresDialect,
|
PostgresDialect
|
||||||
} from "kysely";
|
} from 'kysely'
|
||||||
import * as path from "path";
|
import * as path from 'path'
|
||||||
import { Pool } from "pg";
|
import { Pool } from 'pg'
|
||||||
import Database from "./model";
|
import type Database from './model'
|
||||||
|
|
||||||
async function migrateToLatest() {
|
async function migrateToLatest () {
|
||||||
const db = new Kysely<Database>({
|
const db = new Kysely<Database>({
|
||||||
dialect: new PostgresDialect({
|
dialect: new PostgresDialect({
|
||||||
pool: new Pool({
|
pool: new Pool({
|
||||||
host: process.env.POSTGRES_HOST,
|
host: process.env.POSTGRES_HOST,
|
||||||
database: process.env.POSTGRES_DATABASE,
|
database: process.env.POSTGRES_DATABASE,
|
||||||
user: process.env.POSTGRES_USER,
|
user: process.env.POSTGRES_USER,
|
||||||
password: process.env.POSTGRES_PASSWORD,
|
password: process.env.POSTGRES_PASSWORD
|
||||||
}),
|
})
|
||||||
}),
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
const migrator = new Migrator({
|
const migrator = new Migrator({
|
||||||
db,
|
db,
|
||||||
provider: new FileMigrationProvider({
|
provider: new FileMigrationProvider({
|
||||||
fs,
|
fs,
|
||||||
path,
|
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) => {
|
results?.forEach((it) => {
|
||||||
if (it.status === "Success") {
|
if (it.status === 'Success') {
|
||||||
console.log(`migration "${it.migrationName}" was executed successfully`);
|
console.log(`migration "${it.migrationName}" was executed successfully`)
|
||||||
} else if (it.status === "Error") {
|
} else if (it.status === 'Error') {
|
||||||
console.error(`failed to execute migration "${it.migrationName}"`);
|
console.error(`failed to execute migration "${it.migrationName}"`)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error("failed to migrate");
|
console.error('failed to migrate')
|
||||||
console.error(error);
|
console.error(error)
|
||||||
process.exit(1);
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
await db.destroy();
|
await db.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
export default migrateToLatest;
|
export default migrateToLatest
|
||||||
|
|||||||
Reference in New Issue
Block a user