From 914942dd2fed0c7a16ccbfe638bc046e68731b1d Mon Sep 17 00:00:00 2001 From: Konstantin Wohlwend Date: Mon, 25 Aug 2025 10:13:18 -0700 Subject: [PATCH] Migration summary --- AGENTS.md | 1 + apps/backend/scripts/db-migrations.ts | 34 +++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 831ccb914..17d4120b9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -77,6 +77,7 @@ To see all development ports, refer to the index.html of `apps/dev-launchpad/pub ### Code-related - Use ES6 maps instead of records wherever you can. +- Use `performance.now()` where appropriate for timing deltas, not `Date.now()` ### Testing-related - When writing tests, prefer .toMatchInlineSnapshot over other matchers, if possible. You can check (and modify) the snapshot-serializer.ts file to see how the snapshots are formatted and how non-deterministic values are handled. diff --git a/apps/backend/scripts/db-migrations.ts b/apps/backend/scripts/db-migrations.ts index 037604f4a..461cfdc46 100644 --- a/apps/backend/scripts/db-migrations.ts +++ b/apps/backend/scripts/db-migrations.ts @@ -34,12 +34,42 @@ const promptDropDb = async () => { }; const migrate = async () => { - await applyMigrations({ + const startTime = performance.now(); + const migrationFiles = getMigrationFiles(MIGRATION_FILES_DIR); + const totalMigrations = migrationFiles.length; + + const result = await applyMigrations({ prismaClient: globalPrismaClient, - migrationFiles: getMigrationFiles(MIGRATION_FILES_DIR), + migrationFiles, logging: true, schema: globalPrismaSchema, }); + + const endTime = performance.now(); + const duration = ((endTime - startTime) / 1000).toFixed(2); + + // Print summary + console.log('\n' + '='.repeat(60)); + console.log('šŸ“Š MIGRATION SUMMARY'); + console.log('='.repeat(60)); + console.log(`āœ… Migrations completed successfully`); + console.log(`ā±ļø Duration: ${duration} seconds`); + console.log(`šŸ“ Total migrations in folder: ${totalMigrations}`); + console.log(`šŸ†• Newly applied migrations: ${result.newlyAppliedMigrationNames.length}`); + console.log(`āœ“ Already applied migrations: ${totalMigrations - result.newlyAppliedMigrationNames.length}`); + + if (result.newlyAppliedMigrationNames.length > 0) { + console.log('\nšŸ“ Newly applied migrations:'); + result.newlyAppliedMigrationNames.forEach((name, index) => { + console.log(` ${index + 1}. ${name}`); + }); + } else { + console.log('\n✨ Database is already up to date!'); + } + + console.log('='.repeat(60) + '\n'); + + return result; }; const showHelp = () => {