@@ -43,6 +43,8 @@ import {
4343const dbPatchesFolderPath = path . join ( cwd ( ) , 'db_patches' ) ;
4444const seedsPath = path . join ( dbPatchesFolderPath , 'db_seeds' ) ;
4545
46+ const getDurationMs = ( startedAt : number ) => Date . now ( ) - startedAt ;
47+
4648@injectable ( )
4749export default class PostgresAdminDataSource implements AdminDataSource {
4850 private autoUpgradedDBReady = false ;
@@ -280,20 +282,38 @@ export default class PostgresAdminDataSource implements AdminDataSource {
280282 * NB! This will actually wipe the database
281283 */
282284 async resetDB ( includeSeeds : boolean ) {
285+ const resetStartedAt = Date . now ( ) ;
286+ const shouldApplySeeds = env . INCLUDE_SEEDS === '1' || includeSeeds ;
287+
283288 try {
289+ const dropSchemaStartedAt = Date . now ( ) ;
290+
284291 await database . raw ( `
285292 DROP SCHEMA public CASCADE;
286293 CREATE SCHEMA public;
287294 GRANT ALL ON SCHEMA public TO duouser;
288295 GRANT ALL ON SCHEMA public TO public;
289296 ` ) ;
290297
298+ logger . logInfo ( 'resetDB timing: schema recreated' , {
299+ durationMs : getDurationMs ( dropSchemaStartedAt ) ,
300+ includeSeeds,
301+ shouldApplySeeds,
302+ } ) ;
303+
291304 const applyPatchesOutput = await this . applyPatches ( ) ;
292305
293- if ( env . INCLUDE_SEEDS === '1' || includeSeeds ) {
306+ if ( shouldApplySeeds ) {
294307 await this . applySeeds ( ) ;
295308 }
296309
310+ logger . logInfo ( 'resetDB timing: reset finished' , {
311+ durationMs : getDurationMs ( resetStartedAt ) ,
312+ includeSeeds,
313+ shouldApplySeeds,
314+ patchesApplied : applyPatchesOutput . length ,
315+ } ) ;
316+
297317 return applyPatchesOutput ;
298318 } catch ( e ) {
299319 logger . logException ( 'resetDB failed' , e ) ;
@@ -304,6 +324,7 @@ export default class PostgresAdminDataSource implements AdminDataSource {
304324
305325 async applyPatches ( ) : Promise < string [ ] > {
306326 this . autoUpgradedDBReady = false ;
327+ const applyPatchesStartedAt = Date . now ( ) ;
307328
308329 logger . logInfo ( 'Applying patches started' , { timestamp : new Date ( ) } ) ;
309330
@@ -337,14 +358,19 @@ export default class PostgresAdminDataSource implements AdminDataSource {
337358 } ) ;
338359 }
339360
340- logger . logInfo ( 'Applying patches finished' , { timestamp : new Date ( ) } ) ;
361+ logger . logInfo ( 'Applying patches finished' , {
362+ timestamp : new Date ( ) ,
363+ durationMs : getDurationMs ( applyPatchesStartedAt ) ,
364+ patchesApplied : patches . length ,
365+ } ) ;
341366
342367 this . autoUpgradedDBReady = true ;
343368
344369 return patches . map ( ( [ file ] ) => file ) ;
345370 }
346371
347372 private async applySeeds ( ) {
373+ const applySeedsStartedAt = Date . now ( ) ;
348374 logger . logInfo ( 'Applying seeds started' , { timestamp : new Date ( ) } ) ;
349375
350376 const log : string [ ] = [ ] ;
@@ -372,7 +398,10 @@ export default class PostgresAdminDataSource implements AdminDataSource {
372398 } ) ;
373399 }
374400
375- logger . logInfo ( 'Applying seeds finished' , { } ) ;
401+ logger . logInfo ( 'Applying seeds finished' , {
402+ durationMs : getDurationMs ( applySeedsStartedAt ) ,
403+ seedsApplied : log . length ,
404+ } ) ;
376405 }
377406
378407 protected async upgrade ( ) {
0 commit comments