convex-helpers
Advanced tools
Comparing version 0.1.33 to 0.1.34-alpha.0
@@ -158,2 +158,23 @@ /** | ||
handler: async (ctx, args) => { | ||
if (args.batchSize === 0) { | ||
throw new Error("Batch size must be greater than zero.\n" + | ||
"Running this from the dashboard? Here's some args to use:\n" + | ||
`{ fn: "${args.fn}", cursor: null, dryRun: }`); | ||
} | ||
if (args.cursor === "") { | ||
if (args.dryRun) { | ||
console.warn("Setting cursor to null for dry run"); | ||
args.cursor = null; | ||
} | ||
else { | ||
throw new Error(`Cursor can't be an empty string. | ||
Use null to start from the beginning. | ||
Use undefined / unset to resume from where it left off.`); | ||
} | ||
} | ||
if (args.fn === "" && !args.dryRun) { | ||
// We allow passing an empty string for dry runs. | ||
// They don't need to recursively schedule. | ||
throw new Error("fn must be set if dryRun: false."); | ||
} | ||
// Making a db typed specifically to the migration table. | ||
@@ -170,3 +191,3 @@ const db = ctx.db; | ||
}; | ||
if (migrationTableName) { | ||
if (migrationTableName && args.fn) { | ||
const existing = await db | ||
@@ -177,2 +198,6 @@ .query(migrationTableName) | ||
if (existing) { | ||
if (existing.table !== table) { | ||
throw new Error("Table mismatch: ${existing.table} !== ${table}. " + | ||
"Did you run a migration with the wrong function name?"); | ||
} | ||
state = existing; | ||
@@ -219,3 +244,3 @@ } | ||
}); | ||
throw new Error("Dry run"); | ||
throw new Error("Dry run - rolling back transaction."); | ||
} | ||
@@ -291,3 +316,3 @@ } | ||
console.debug({ args, state }); | ||
throw new Error("Dry run"); | ||
throw new Error("Dry run - rolling back transaction."); | ||
} | ||
@@ -294,0 +319,0 @@ return state; |
{ | ||
"name": "convex-helpers", | ||
"version": "0.1.33", | ||
"version": "0.1.34-alpha.0", | ||
"description": "A collection of useful code to complement the official convex package.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -222,2 +222,25 @@ /** | ||
handler: async (ctx, args) => { | ||
if (args.batchSize === 0) { | ||
throw new Error( | ||
"Batch size must be greater than zero.\n" + | ||
"Running this from the dashboard? Here's some args to use:\n" + | ||
`{ fn: "${args.fn}", cursor: null, dryRun: }` | ||
); | ||
} | ||
if (args.cursor === "") { | ||
if (args.dryRun) { | ||
console.warn("Setting cursor to null for dry run"); | ||
args.cursor = null; | ||
} else { | ||
throw new Error(`Cursor can't be an empty string. | ||
Use null to start from the beginning. | ||
Use undefined / unset to resume from where it left off.`); | ||
} | ||
} | ||
if (args.fn === "" && !args.dryRun) { | ||
// We allow passing an empty string for dry runs. | ||
// They don't need to recursively schedule. | ||
throw new Error("fn must be set if dryRun: false."); | ||
} | ||
// Making a db typed specifically to the migration table. | ||
@@ -238,3 +261,3 @@ const db = ctx.db as unknown as GenericDatabaseWriter< | ||
}; | ||
if (migrationTableName) { | ||
if (migrationTableName && args.fn) { | ||
const existing = await db | ||
@@ -245,2 +268,8 @@ .query(migrationTableName) | ||
if (existing) { | ||
if (existing.table !== table) { | ||
throw new Error( | ||
"Table mismatch: ${existing.table} !== ${table}. " + | ||
"Did you run a migration with the wrong function name?" | ||
); | ||
} | ||
state = existing as MigrationDoc; | ||
@@ -286,3 +315,3 @@ } else { | ||
}); | ||
throw new Error("Dry run"); | ||
throw new Error("Dry run - rolling back transaction."); | ||
} | ||
@@ -366,3 +395,3 @@ } else { | ||
console.debug({ args, state }); | ||
throw new Error("Dry run"); | ||
throw new Error("Dry run - rolling back transaction."); | ||
} | ||
@@ -369,0 +398,0 @@ return state; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
492638
8966