feat: fix migrations logging
This commit is contained in:
parent
8ebb1c95dc
commit
30f79fc6c3
@ -1,3 +1,4 @@
|
||||
import path from 'node:path'
|
||||
import { migrateDatabase } from '@boring.tools/database'
|
||||
import { logger } from '@boring.tools/logger'
|
||||
|
||||
@ -36,5 +37,11 @@ export const startup = async () => {
|
||||
await migrateDatabase('migrations')
|
||||
}
|
||||
|
||||
if (import.meta.env.NODE_ENV === 'development') {
|
||||
await migrateDatabase(
|
||||
path.join(__dirname, '../../../../packages/database/src/migrations'),
|
||||
)
|
||||
}
|
||||
|
||||
logger.info('API started')
|
||||
}
|
||||
|
@ -1,14 +1,12 @@
|
||||
import { logger } from '@boring.tools/logger'
|
||||
import { migrate } from 'drizzle-orm/postgres-js/migrator'
|
||||
import { client, db } from './'
|
||||
import { db } from './'
|
||||
|
||||
export const migrateDatabase = async (dir: string) => {
|
||||
try {
|
||||
await migrate(db, { migrationsFolder: dir })
|
||||
await client.end()
|
||||
logger.log('Migrations: Ok')
|
||||
logger.info('Migrations: Ok')
|
||||
} catch (error) {
|
||||
logger.error('Migrations: Failed')
|
||||
logger.error(error)
|
||||
logger.error('Migrations: Failed', error)
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,20 @@ import winston from 'winston'
|
||||
|
||||
// Create a Winston logger - passing in the Logtail transport
|
||||
export const logger = winston.createLogger({
|
||||
format: winston.format.json(),
|
||||
transports: [],
|
||||
})
|
||||
|
||||
if (import.meta.env.NODE_ENV !== 'test') {
|
||||
if (import.meta.env.NODE_ENV === 'production') {
|
||||
// Create a Logtail client
|
||||
const logtail = new Logtail(process.env.BETTERSTACK_LOG_TOKEN as string)
|
||||
logger.add(new LogtailTransport(logtail))
|
||||
}
|
||||
|
||||
if (import.meta.env.NODE_ENV === 'development') {
|
||||
logger.add(
|
||||
new winston.transports.Console({
|
||||
format: winston.format.json(),
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user