diff --git a/packages/db/prisma/data-migrations/2023-09-20_update-services.ts b/packages/db/prisma/data-migrations/2023-09-20_update-services.ts index ab473e06e7..d3f8a6779c 100644 --- a/packages/db/prisma/data-migrations/2023-09-20_update-services.ts +++ b/packages/db/prisma/data-migrations/2023-09-20_update-services.ts @@ -50,6 +50,7 @@ export const job20230920_update_services = { tagId: 'svtg_01HAD99DSF7TH2HDXNYC331BVN', active: true, })), + skipDuplicates: true, }) log(`Created ${gaCareTag.count} tags for ${tGaCare.length} services`) }) diff --git a/packages/db/prisma/dataMigrationRunner.ts b/packages/db/prisma/dataMigrationRunner.ts index 19f645a765..5af27294e9 100644 --- a/packages/db/prisma/dataMigrationRunner.ts +++ b/packages/db/prisma/dataMigrationRunner.ts @@ -2,9 +2,11 @@ import { Listr, type ListrDefaultRenderer, + type ListrSimpleRenderer, type ListrTask as ListrTaskObj, type ListrTaskWrapper, PRESET_TIMER, + PRESET_TIMESTAMP, } from 'listr2' import { prisma } from '~db/client' @@ -18,12 +20,13 @@ import * as jobList from './data-migrations' * You shouldn't need to touch anything in this file. All jobs in `data-migrations/index.ts` will be imported. */ -const renderOptions = { - bottomBar: 10, +const rendererOptions = { + outputBar: 10, persistentOutput: true, timer: PRESET_TIMER, -} satisfies ListrJob['options'] -const injectOptions = (job: ListrJob): ListrJob => ({ ...job, options: renderOptions }) +} satisfies ListrJob['rendererOptions'] + +const injectOptions = (job: ListrJob): ListrJob => ({ ...job, rendererOptions }) const jobQueue: ListrJob[] = [] @@ -50,24 +53,23 @@ const jobs = new Listr( if (jobNamesToRun.length) { ctx.pendingMigrations = true ctx.jobCount = jobNamesToRun.length - task.output = `${jobNamesToRun.length} migrations to run:\n${jobNamesToRun.join('\n')}` + task.output = `${jobNamesToRun.length} migrations to run:\n▸ ${jobNamesToRun.join('\n▸ ')}` task.title = `Pending migrations: ${jobNamesToRun.length}` } else { - task.title = `No pending migrations` + task.title = `No pending migrations to apply.` } }, - ...renderOptions, + + rendererOptions: { ...rendererOptions, timer: { condition: false, field: '' } }, }, { - title: `Apply ${jobQueue.length} pending migrations`, task: (ctx, task) => { - task.title = `Apply ${ctx.jobCount ?? 0} pending migrations` + task.title = `Applying ${ctx.jobCount ?? 0} pending migrations` return task.newListr(jobQueue) }, enabled: (ctx) => !!ctx.pendingMigrations, - ...renderOptions, + rendererOptions, }, - // ...Object.values(jobList).map((job) => injectOptions(job)), ], { rendererOptions: { @@ -75,12 +77,13 @@ const jobs = new Listr( timer: PRESET_TIMER, suffixSkips: true, collapseSubtasks: false, + removeEmptyLines: false, }, fallbackRendererOptions: { timer: PRESET_TIMER, + timestamp: PRESET_TIMESTAMP, }, exitOnError: false, - forceColor: true, } ) @@ -91,7 +94,7 @@ export type Context = { pendingMigrations?: boolean jobCount?: number } -export type PassedTask = ListrTaskWrapper +export type PassedTask = ListrTaskWrapper export type ListrJob = ListrTaskObj export type MigrationJob = ListrJob & { def: JobDef } diff --git a/packages/db/prisma/jobPreRun.ts b/packages/db/prisma/jobPreRun.ts index 3de3988bd8..a72c6be338 100644 --- a/packages/db/prisma/jobPreRun.ts +++ b/packages/db/prisma/jobPreRun.ts @@ -7,10 +7,10 @@ import path from 'path' import { type PassedTask } from './dataMigrationRunner' import { prisma } from '..' -const getTimestamp = () => DateTime.now().toLocaleString(DateTime.TIME_24_WITH_SECONDS).replaceAll(':', '.') +const getTimestamp = () => DateTime.now().toFormat('yyyy-MM-dd_HH.mm.ss') const logFile = (file: string, output: string) => { - const timestamp = DateTime.now().toFormat('yyyy-MM-dd HH:mm:ss') + const timestamp = DateTime.now().toFormat('yyyy-MM-dd HH:mm:ss.SSS') const outFile = path.resolve(__dirname, './migration-logs/', file) const formattedOutput = `[${timestamp}] ${output}\n` fs.writeFileSync(outFile, formattedOutput, { flag: 'a' })