Skip to content

Email for professionals and teams

fix(backups): finish the D1 export and read the nested signed URL

Bruce McLachlan57335e943144
diff --git a/src/lib/backups/types.d.ts b/src/lib/backups/types.d.ts
index 9a7847a..927f9ba 100644
--- a/src/lib/backups/types.d.ts
+++ b/src/lib/backups/types.d.ts
@@ -7,8 +7,14 @@ export type BackupWorkflowParams = {
export type D1ExportResult = {
at_bookmark?: string;
+ status?: string;
+ error?: string;
signed_url?: string;
filename?: string;
+ result?: {
+ signed_url?: string;
+ filename?: string;
+ };
};
export type D1ExportResponse = {
diff --git a/src/lib/backups/workflow.ts b/src/lib/backups/workflow.ts
index a97cc9a..258bbec 100644
--- a/src/lib/backups/workflow.ts
+++ b/src/lib/backups/workflow.ts
@@ -44,11 +44,14 @@ export class DatabaseBackupWorkflow extends WorkflowEntrypoint<CloudflareEnv, Ba
let exportFilename = "";
for (let attempt = 1; attempt <= EXPORT_RETRIES; attempt += 1) {
const result = await step.do(`Poll D1 export ${attempt}`, async () =>
- this.callExportApi(exportUrl, { current_bookmark: bookmark }),
+ this.callExportApi(exportUrl, { output_format: "polling", current_bookmark: bookmark }),
);
- if (result.result?.signed_url) {
- signedUrl = result.result.signed_url;
- exportFilename = result.result.filename ?? "";
+ // The polling response nests the finished export one level deeper
+ // (result.result.result); fall back to the flat shape defensively.
+ const finished = result.result?.result ?? result.result;
+ if (finished?.signed_url) {
+ signedUrl = finished.signed_url;
+ exportFilename = finished.filename ?? "";
break;
}
if (attempt < EXPORT_RETRIES) await step.sleep(`Wait for D1 export ${attempt}`, "15 seconds");