@@ -26,6 +26,7 @@ export type { MigrationArgs, MigrationResult, MigrationStatus };
2626
2727import { ConvexError , type GenericId } from "convex/values" ;
2828import type { ComponentApi } from "../component/_generated/component.js" ;
29+ import { logStatusAndInstructions } from "./log.js" ;
2930
3031// Note: this value is hard-coded in the docstring below. Please keep in sync.
3132export const DEFAULT_BATCH_SIZE = 100 ;
@@ -608,82 +609,6 @@ export type MigrationFunctionReference = FunctionReference<
608609 MigrationArgs
609610> ;
610611
611-
612- function logStatusAndInstructions (
613- name : string ,
614- status : MigrationStatus ,
615- args : {
616- fn ?: string ;
617- cursor ?: string | null ;
618- batchSize ?: number ;
619- dryRun ?: boolean ;
620- } ,
621- ) {
622- const output : Record < string , unknown > = { } ;
623- if ( status . isDone ) {
624- if ( status . latestEnd ! < Date . now ( ) ) {
625- output [ "Status" ] = "Migration already done." ;
626- } else if ( status . latestStart === status . latestEnd ) {
627- output [ "Status" ] = "Migration was started and finished in one batch." ;
628- } else {
629- output [ "Status" ] = "Migration completed with this batch." ;
630- }
631- } else {
632- if ( status . state === "failed" ) {
633- output [ "Status" ] = `Migration failed: ${ status . error } ` ;
634- } else if ( status . state === "canceled" ) {
635- output [ "Status" ] = "Migration canceled." ;
636- } else if ( status . latestStart >= Date . now ( ) ) {
637- output [ "Status" ] = "Migration started." ;
638- } else {
639- output [ "Status" ] = "Migration running." ;
640- }
641- }
642- if ( args . dryRun ) {
643- output [ "DryRun" ] = "No changes were committed." ;
644- output [ "Status" ] = "DRY RUN: " + output [ "Status" ] ;
645- }
646- output [ "Name" ] = name ;
647- output [ "lastStarted" ] = new Date ( status . latestStart ) . toISOString ( ) ;
648- if ( status . latestEnd ) {
649- output [ "lastFinished" ] = new Date ( status . latestEnd ) . toISOString ( ) ;
650- }
651- output [ "processed" ] = status . processed ;
652- if ( status . next ?. length ) {
653- if ( status . isDone ) {
654- output [ "nowUp" ] = status . next ;
655- } else {
656- output [ "nextUp" ] = status . next ;
657- }
658- }
659- const nextArgs = ( status . next || [ ] ) . map ( ( n ) => `"${ n } "` ) . join ( ", " ) ;
660- const run = `npx convex run --component migrations` ;
661- if ( ! args . dryRun ) {
662- if ( status . state === "inProgress" ) {
663- output [ "toCancel" ] = {
664- cmd : `${ run } lib:cancel` ,
665- args : `{"name": "${ name } "}` ,
666- prod : `--prod` ,
667- } ;
668- output [ "toMonitorStatus" ] = {
669- cmd : `${ run } --watch lib:getStatus` ,
670- args : `{"names": ["${ name } "${ status . next ?. length ? ", " + nextArgs : "" } ]}` ,
671- prod : `--prod` ,
672- } ;
673- } else {
674- output [ "toStartOver" ] = JSON . stringify ( { ...args , cursor : null } ) ;
675- if ( status . next ?. length ) {
676- output [ "toMonitorStatus" ] = {
677- cmd : `${ run } --watch lib:getStatus` ,
678- args : `{"names": [${ nextArgs } ]}` ,
679- prod : `--prod` ,
680- } ;
681- }
682- }
683- }
684- return output ;
685- }
686-
687612/* Type utils follow */
688613
689614type QueryCtx = Pick < GenericQueryCtx < GenericDataModel > , "runQuery" > ;
0 commit comments