Repository navigation
upgrade duckdb and add script to download extensions - #1043
Conversation
WalkthroughThis 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
|
There was a problem hiding this comment.
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
.sha256files), you could:
- Download both the extension and its checksum file
- Verify the downloaded extension matches the checksum
- 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
⛔ Files ignored due to path filters (6)
web/public/duckdb-extensions/v1.1.1/wasm_eh/json.duckdb_extension.wasmis excluded by!**/*.wasmweb/public/duckdb-extensions/v1.1.1/wasm_eh/parquet.duckdb_extension.wasmis excluded by!**/*.wasmweb/public/duckdb-extensions/v1.4.0/wasm_eh/httpfs.duckdb_extension.wasmis excluded by!**/*.wasmweb/public/duckdb-extensions/v1.4.0/wasm_eh/json.duckdb_extension.wasmis excluded by!**/*.wasmweb/public/duckdb-extensions/v1.4.0/wasm_eh/parquet.duckdb_extension.wasmis excluded by!**/*.wasmweb/yarn.lockis 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.,
postinstallorbuild). 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:
- Automatically during
postinstall(afternpm install)?- As part of the
buildprocess?- Manually only when upgrading DuckDB?
- 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-wasmand@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 to1.31.0. The versioning schemes intentionally differ between the DuckDB engine (v1.x.x) and the NPM package (1.x.x format).
| 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); | ||
| }); | ||
| } |
There was a problem hiding this comment.
Add timeout and redirect handling to prevent hangs and handle CDN redirects.
The download function has these issues:
- No timeout on the HTTPS request - could hang indefinitely if the server is slow or unresponsive
- Only accepts status code 200 - doesn't handle 3xx redirects that CDNs commonly use
- 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.
| 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.



Summary by CodeRabbit