Skip to content

upgrade duckdb and add script to download extensions - #1043

Merged
ddecrulle merged 1 commit into
mainfrom
upgrade-duckdb
Oct 30, 2025
Merged

ddecrulle merged 1 commit into
mainfrom
upgrade-duckdb

Conversation

@ddecrulle

@ddecrulle ddecrulle commented Oct 29, 2025 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Dependencies
    • Upgraded DuckDB WASM dependencies to version 1.31.0, bringing latest improvements and fixes to database functionality.

@ddecrulle
ddecrulle requested a review from garronej October 29, 2025 14:58
@coderabbitai

coderabbitai Bot commented Oct 29, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This PR updates DuckDB WASM dependencies from 1.29.0 to 1.31.0 and introduces a new automated script that downloads and manages DuckDB WASM extensions locally. The script downloads default extensions (parquet, json, httpfs) and stores them in the project's public directory for distribution.

Changes

Cohort / File(s) Change Summary
Package Configuration
web/package.json
Added new script update-duckdb-extensions to scripts section; bumped @duckdb/duckdb-wasm and @duckdb/duckdb-wasm-shell dependencies from 1.29.0 to 1.31.0
Extension Management Script
web/scripts/update-duckdb-extensions.ts
New TypeScript script that automates downloading DuckDB WASM extensions; manages directory cleanup, extension downloads via HTTPS, and error handling for extension management

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Dependency version bumps are straightforward
  • New script follows a standard pattern for downloading and file management
  • Consider reviewing:
    • Correctness of the BASE_URL and extension download URLs
    • Network error handling and retry logic completeness
    • Directory permissions and cleanup operations

Poem

🐰 We hop along with extensions in tow,
DuckDB updated, now 1.31's glow,
Scripts download swiftly, files tucked away,
Public and ready for build's big day! 🎉

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "upgrade duckdb and add script to download extensions" clearly and concisely captures the two main components of the changeset: the version bump of DuckDB WASM dependencies from 1.29.0 to 1.31.0, and the addition of the new update-duckdb-extensions.ts script along with its corresponding npm script entry. The title is specific and descriptive enough that a teammate reviewing the repository history would understand the primary changes without ambiguity, and it avoids vague terminology or unnecessary details.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch upgrade-duckdb

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
web/scripts/update-duckdb-extensions.ts (2)

23-40: Consider adding integrity validation for downloaded extensions.

The script downloads extensions without verifying their integrity. Adding checksum validation would ensure the downloaded files match expected values and haven't been corrupted or tampered with.

If DuckDB provides checksums for extensions (often as .sha256 files), you could:

  1. Download both the extension and its checksum file
  2. Verify the downloaded extension matches the checksum
  3. Reject downloads that fail validation

This would improve security and reliability, especially since these extensions are served directly to users.


48-56: Consider parallelizing downloads for faster execution.

Extensions are currently downloaded sequentially. Using Promise.all() would download them concurrently, reducing total execution time.

Apply this diff to parallelize downloads:

-    for (const ext of DEFAULT_EXTS) {
-        const fileName = `${ext}.duckdb_extension.wasm`;
-        const url = `${BASE_URL}/${fileName}`;
-        const dest = path.join(OUTPUT_DIR, fileName);
-
-        console.log(`⬇️  Downloading ${ext} extension...`);
-        await download(url, dest);
-        console.log(`   ✅ Saved to ${dest}`);
-    }
+    await Promise.all(
+        DEFAULT_EXTS.map(async ext => {
+            const fileName = `${ext}.duckdb_extension.wasm`;
+            const url = `${BASE_URL}/${fileName}`;
+            const dest = path.join(OUTPUT_DIR, fileName);
+
+            console.log(`⬇️  Downloading ${ext} extension...`);
+            await download(url, dest);
+            console.log(`   ✅ Saved to ${dest}`);
+        })
+    );
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2886bac and ab0eedb.

⛔ Files ignored due to path filters (6)
  • web/public/duckdb-extensions/v1.1.1/wasm_eh/json.duckdb_extension.wasm is excluded by !**/*.wasm
  • web/public/duckdb-extensions/v1.1.1/wasm_eh/parquet.duckdb_extension.wasm is excluded by !**/*.wasm
  • web/public/duckdb-extensions/v1.4.0/wasm_eh/httpfs.duckdb_extension.wasm is excluded by !**/*.wasm
  • web/public/duckdb-extensions/v1.4.0/wasm_eh/json.duckdb_extension.wasm is excluded by !**/*.wasm
  • web/public/duckdb-extensions/v1.4.0/wasm_eh/parquet.duckdb_extension.wasm is excluded by !**/*.wasm
  • web/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (2)
  • web/package.json (2 hunks)
  • web/scripts/update-duckdb-extensions.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test_web
🔇 Additional comments (4)
web/package.json (3)

21-21: Clarify when the update-duckdb-extensions script should be executed.

The new script is not integrated into the build pipeline (e.g., postinstall or build). Developers must remember to run it manually, which could lead to:

  • Missing extensions in development/production
  • Version mismatches if DuckDB is upgraded but extensions aren't updated

Should this script run:

  1. Automatically during postinstall (after npm install)?
  2. As part of the build process?
  3. Manually only when upgrading DuckDB?
  4. In CI/CD before builds/deployments?

If it should run automatically, consider adding it to the appropriate lifecycle hook. Otherwise, document in the README when developers should run npm run update-duckdb-extensions.


20-20: LGTM - Prestorybook script looks correct.

The prestorybook script correctly runs the unyamlify-env-local script before starting Storybook. This ensures environment configuration is set up properly.

Note: The AI summary mentions "multiple prestorybook tasks" but only one command is visible. If there were additional changes intended, please verify the prestorybook workflow is complete.


38-39: DuckDB WASM packages are updated to the latest stable version with no breaking changes identified.

v1.31.0 is the latest release (Sep 26, 2025), which is confirmed in package.json for both @duckdb/duckdb-wasm and @duckdb/duckdb-wasm-shell. v1.29.0 aligned with DuckDB v1.1.1, while v1.30.0 targeted DuckDB v1.3.2, and v1.31.0 is based on DuckDB v1.4.0. The version increments are minor with no reported API or breaking changes in the upgrade path. The codebase can safely proceed with this upgrade.

web/scripts/update-duckdb-extensions.ts (1)

6-6: No issues found—original review comment was incorrect.

DuckDB-Wasm v1.31.0 is based on (compatible with) DuckDB engine v1.4.0. The script correctly uses engine version v1.4.0, which is compatible with the NPM package upgrade to 1.31.0. The versioning schemes intentionally differ between the DuckDB engine (v1.x.x) and the NPM package (1.x.x format).

Comment on lines +23 to +40
async function download(url: string, dest: string) {
return new Promise<void>((resolve, reject) => {
https
.get(url, res => {
if (res.statusCode !== 200) {
reject(new Error(`Failed to download ${url} (${res.statusCode})`));
return;
}

const writable = fs.createWriteStream(dest);
res.pipe(writable);

writable.on("finish", () => resolve());
writable.on("error", reject);
})
.on("error", reject);
});
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add timeout and redirect handling to prevent hangs and handle CDN redirects.

The download function has these issues:

  1. No timeout on the HTTPS request - could hang indefinitely if the server is slow or unresponsive
  2. Only accepts status code 200 - doesn't handle 3xx redirects that CDNs commonly use
  3. Partial downloads leave corrupt files without cleanup

Apply this diff to add timeout and redirect handling:

-async function download(url: string, dest: string) {
+async function download(url: string, dest: string, maxRedirects = 5) {
     return new Promise<void>((resolve, reject) => {
-        https
-            .get(url, res => {
+        const request = https
+            .get(url, { timeout: 30000 }, res => {
-                if (res.statusCode !== 200) {
+                // Handle redirects
+                if (res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 307 || res.statusCode === 308) {
+                    if (maxRedirects > 0 && res.headers.location) {
+                        resolve(download(res.headers.location, dest, maxRedirects - 1));
+                        return;
+                    }
+                    reject(new Error(`Too many redirects for ${url}`));
+                    return;
+                }
+                
+                if (res.statusCode !== 200) {
                     reject(new Error(`Failed to download ${url} (${res.statusCode})`));
                     return;
                 }
 
                 const writable = fs.createWriteStream(dest);
                 res.pipe(writable);
 
                 writable.on("finish", () => resolve());
-                writable.on("error", reject);
+                writable.on("error", err => {
+                    fs.unlink(dest, () => reject(err));
+                });
             })
+            .on("timeout", () => {
+                request.destroy();
+                fs.unlink(dest, () => reject(new Error(`Download timeout for ${url}`)));
+            })
             .on("error", reject);
     });
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async function download(url: string, dest: string) {
return new Promise<void>((resolve, reject) => {
https
.get(url, res => {
if (res.statusCode !== 200) {
reject(new Error(`Failed to download ${url} (${res.statusCode})`));
return;
}
const writable = fs.createWriteStream(dest);
res.pipe(writable);
writable.on("finish", () => resolve());
writable.on("error", reject);
})
.on("error", reject);
});
}
async function download(url: string, dest: string, maxRedirects = 5) {
return new Promise<void>((resolve, reject) => {
const request = https
.get(url, { timeout: 30000 }, res => {
// Handle redirects
if (res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 307 || res.statusCode === 308) {
if (maxRedirects > 0 && res.headers.location) {
resolve(download(res.headers.location, dest, maxRedirects - 1));
return;
}
reject(new Error(`Too many redirects for ${url}`));
return;
}
if (res.statusCode !== 200) {
reject(new Error(`Failed to download ${url} (${res.statusCode})`));
return;
}
const writable = fs.createWriteStream(dest);
res.pipe(writable);
writable.on("finish", () => resolve());
writable.on("error", err => {
fs.unlink(dest, () => reject(err));
});
})
.on("timeout", () => {
request.destroy();
fs.unlink(dest, () => reject(new Error(`Download timeout for ${url}`)));
})
.on("error", reject);
});
}
🤖 Prompt for AI Agents
In web/scripts/update-duckdb-extensions.ts around lines 23 to 40, the download
function must be hardened: implement a request timeout (set a timer, call
req.destroy()/abort on timeout and reject with a timeout error), follow HTTP 3xx
redirects (handle 301/302/303/307/308 by reading the Location header, limit
redirects with a maxRedirects parameter and recursively or iteratively request
the new URL), only treat the final response status codes in the 2xx range as
successful, and ensure cleanup on errors/timeouts (close/finish the writable
stream and unlink the partial destination file if created, and remove event
listeners to avoid leaks). Add proper error propagation and ensure the stream is
only resolved after 'finish' and rejected on any error, including aborted
requests and non-success final responses.

@ddecrulle
ddecrulle merged commit 49d8472 into main Oct 30, 2025
@ddecrulle
ddecrulle deleted the upgrade-duckdb branch October 30, 2025 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant