Skip to content

Commit 12acfec

Browse files
committed
runToCompletion
1 parent 86e65ce commit 12acfec

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,22 +445,22 @@ await migrations.cancel(ctx, "myNewMutation");
445445
## Running migrations synchronously
446446

447447
If you want to run a migration synchronously from a test or action, you can use
448-
`runSynchronously`. Note that if the action crashes or is canceled, it will not
448+
`runToCompletion`. Note that if the action crashes or is canceled, it will not
449449
continue migrating in the background.
450450

451451
From an action:
452452

453453
```ts
454454
import { components, internal } from "./_generated/api";
455455
import { internalAction } from "./_generated/server";
456-
import { runSynchronously } from "@convex-dev/migrations";
456+
import { runToCompletion } from "@convex-dev/migrations";
457457

458458
export const myAction = internalAction({
459459
args: {},
460460
handler: async (ctx) => {
461461
//...
462462
const toRun = internal.example.setDefaultValue;
463-
await runSynchronously(ctx, components.migrations, toRun);
463+
await runToCompletion(ctx, components.migrations, toRun);
464464
},
465465
});
466466
```
@@ -471,7 +471,7 @@ In a test:
471471
import { test } from "vitest";
472472
import { convexTest } from "convex-test";
473473
import component from "@convex-dev/migrations/test";
474-
import { runSynchronously } from "@convex-dev/migrations";
474+
import { runToCompletion } from "@convex-dev/migrations";
475475
import { components, internal } from "./_generated/api";
476476
import schema from "./schema";
477477

@@ -486,7 +486,7 @@ test("test setDefaultValue migration", async () => {
486486

487487
// Run the migration to completion
488488
const migrationToTest = internal.example.setDefaultValue;
489-
await runSynchronously(ctx, components.migrations, migrationToTest);
489+
await runToCompletion(ctx, components.migrations, migrationToTest);
490490

491491
// Assert that the migration was successful by checking the data
492492
const docs = await ctx.db.query("myTable").collect();

example/convex/example.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
22
import { initConvexTest } from "./setup.test";
33
import { components, internal } from "./_generated/api";
4-
import { runSynchronously } from "@convex-dev/migrations";
4+
import { runToCompletion } from "@convex-dev/migrations";
55

66
describe("example", () => {
77
beforeEach(async () => {
@@ -21,7 +21,7 @@ describe("example", () => {
2121
expect(docs.some((doc) => doc.optionalField === undefined)).toBe(true);
2222
});
2323
await t.run(async (ctx) => {
24-
await runSynchronously(
24+
await runToCompletion(
2525
ctx,
2626
components.migrations,
2727
internal.example.setDefaultValue,
@@ -40,7 +40,7 @@ describe("example", () => {
4040
await t.mutation(internal.example.seed, { count: 10 });
4141
await expect(
4242
t.run(async (ctx) => {
43-
await runSynchronously(
43+
await runToCompletion(
4444
ctx,
4545
components.migrations,
4646
internal.example.failingMigration,

src/client/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ export type MigrationFunctionReference = FunctionReference<
616616
* ```ts
617617
* // In an action
618618
* const toRun = internal.migrations.myMigration;
619-
* await runSynchronously(ctx, components.migrations, toRun);
619+
* await runToCompletion(ctx, components.migrations, toRun);
620620
* ```
621621
*
622622
* If it's already in progress, it will no-op.
@@ -634,7 +634,7 @@ export type MigrationFunctionReference = FunctionReference<
634634
* @param opts Options to start the migration.
635635
* It's helpful to see what it would do without committing the transaction.
636636
*/
637-
export async function runSynchronously(
637+
export async function runToCompletion(
638638
ctx: ActionCtx,
639639
component: ComponentApi,
640640
fnRef: MigrationFunctionReference,

0 commit comments

Comments
 (0)