fix: stream database dumps to support large databases#128
Open
avasis-ai wants to merge 1 commit intoouterbase:mainfrom
Open
fix: stream database dumps to support large databases#128avasis-ai wants to merge 1 commit intoouterbase:mainfrom
avasis-ai wants to merge 1 commit intoouterbase:mainfrom
Conversation
- Replace in-memory string accumulation with ReadableStream response - Fetch table data in batches (LIMIT/OFFSET) to reduce memory pressure - Properly escape SQL identifiers and values (fixes injection vulnerability) - Wrap dump in BEGIN TRANSACTION/COMMIT for atomicity - Fix Content-Type to text/sql for SQL text dumps - Skip internal tmp_* tables from dump output /claim outerbase#59
Author
Author
|
Hey @Brayden — noticed you merged a couple other PRs recently. This one's been sitting for a bit, happy to rebase if main has moved. The streaming approach should handle databases up to the DO limit without OOM. Let me know if you'd like any changes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #59 — Database dumps fail on large databases due to loading the entire dump into memory.
Changes
ReadableStreamresponse, avoiding memory exhaustion on large databasesLIMIT/OFFSETbatches (500 rows) to fetch table data incrementally instead of loading entire tables at onceBEGIN TRANSACTION/COMMITfor atomicitytext/sqlinstead ofapplication/x-sqlite3since the output is SQL text, not a binary SQLite filetmp_*tables from the dump outputHow it works
ReadableStreamthat iterates through tables one at a timeLIMIT ? OFFSET ?INSERTstatements as they're generated, flushing in ~8KB chunksTesting
All 9 dump tests pass, including new tests for:
/claim #59