Skip to content

Commit

Permalink
Merge pull request #8 from get-convex/ian/logging
Browse files Browse the repository at this point in the history
improve logging and default handling
  • Loading branch information
ianmacartney authored Feb 6, 2025
2 parents dd24411 + e942f1c commit 7d82e47
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
39 changes: 16 additions & 23 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,37 +300,30 @@ export class Migrations<DataModel extends GenericDataModel> {
return (await this._runInteractive(ctx, args)) as any;
} else if (args.next?.length) {
throw new Error("You can only pass next if you also provide fn");
}
const numItems = args.batchSize || defaultBatchSize;
if (!args.batchSize) {
if (args.batchSize === 0) {
console.warn(`Batch size is zero. Using the default: ${numItems}`);
}
console.warn(
"Running this from the dashboard? Here's some args to use:"
);
console.warn({
"Dry run": '{ "dryRun": true, "cursor": null }',
"For real": '{ "fn": "path/to/migrations:yourFnName" }',
});
}
if (
(args.cursor === undefined || args.cursor === "") &&
args.dryRun === undefined
} else if (
args.cursor === undefined ||
args.cursor === "" ||
args.dryRun === undefined ||
args.batchSize === 0
) {
console.warn(
"No cursor or dryRun specified - doing a dry run on the next batch" +
"Running this from the CLI or dashboard? Here's some args to use:"
"Running this from the CLI or dashboard? Here's some args to use:"
);
console.warn({
"Dry run": '{ "dryRun": true, "cursor": null }',
"For real": '{ "fn": "path/to/migrations:yourFnName" }',
});
args.cursor = null;
args.dryRun = true;
}
if (args.cursor === "" || args.cursor === undefined) {
if (args.dryRun) {

const numItems = args.batchSize || defaultBatchSize;
if (args.cursor === undefined || args.cursor === "") {
if (args.dryRun === undefined) {
console.warn(
"No cursor or dryRun specified - doing a dry run on the next batch."
);
args.cursor = null;
args.dryRun = true;
} else if (args.dryRun) {
console.warn("Setting cursor to null for dry run");
args.cursor = null;
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/component/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export const migrate = mutation({
handler: async (ctx, args) => {
// Step 1: Get or create the state.
const { fnHandle, batchSize, next: next_, dryRun, ...initialState } = args;
if (batchSize !== undefined && batchSize <= 0) {
throw new Error("Batch size must be greater than 0");
}
if (!fnHandle.startsWith("function://")) {
throw new Error(
"Invalid fnHandle.\n" +
Expand Down

0 comments on commit 7d82e47

Please sign in to comment.