@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
22import { initConvexTest } from "./setup.test" ;
33import { components , internal } from "./_generated/api" ;
44import { runToCompletion } from "@convex-dev/migrations" ;
5+ import { createFunctionHandle , getFunctionName } from "convex/server" ;
56
67describe ( "example" , ( ) => {
78 beforeEach ( async ( ) => {
@@ -48,4 +49,28 @@ describe("example", () => {
4849 } ) ,
4950 ) . rejects . toThrow ( "This migration fails after the first" ) ;
5051 } ) ;
52+
53+ test ( "test migrating with function handle" , async ( ) => {
54+ const t = initConvexTest ( ) ;
55+ await t . mutation ( internal . example . seed , { count : 10 } ) ;
56+ await t . run ( async ( ctx ) => {
57+ const docs = await ctx . db . query ( "myTable" ) . collect ( ) ;
58+ expect ( docs ) . toHaveLength ( 10 ) ;
59+ expect ( docs . some ( ( doc ) => doc . optionalField === undefined ) ) . toBe ( true ) ;
60+ } ) ;
61+ await t . run ( async ( ctx ) => {
62+ const fnHandle = await createFunctionHandle (
63+ internal . example . setDefaultValue ,
64+ ) ;
65+ await runToCompletion ( ctx , components . migrations , fnHandle , {
66+ name : getFunctionName ( internal . example . setDefaultValue ) ,
67+ batchSize : 2 ,
68+ } ) ;
69+ } ) ;
70+ await t . run ( async ( ctx ) => {
71+ const after = await ctx . db . query ( "myTable" ) . collect ( ) ;
72+ expect ( after ) . toHaveLength ( 10 ) ;
73+ expect ( after . every ( ( doc ) => doc . optionalField !== undefined ) ) . toBe ( true ) ;
74+ } ) ;
75+ } ) ;
5176} ) ;
0 commit comments