/claim #59
Fixes: #59
This PR implements a robust solution for handling large database dumps that exceed the 30-second request timeout limit and memory constraints.
The current implementation has two critical limitations:
This solution implements chunked processing with R2 storage to handle databases up to 10GB in size.
Chunked Processing
R2 Storage Integration
dump_YYYYMMDD-HHMMSS.{format}
Processing Control
Progress Tracking
Add to your wrangler.toml
:
[[r2_buckets]]
binding = "DATABASE_DUMPS"
bucket_name = "your-database-dumps-bucket"
preview_bucket_name = "your-test-bucket" # Optional: for local testing
[vars]
DUMP_CHUNK_SIZE = "1000" # Optional: Default chunk size
DUMP_BREATHING_INTERVAL = "5000" # Optional: Pause duration in ms
MAX_EXECUTION_TIME = "25000" # Optional: Time before breathing
curl --location 'https://starbasedb.YOUR-ID-HERE.workers.dev/export/dump' \
--header 'Authorization: Bearer YOUR-TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"format": "sql", # Required: sql|csv|json
"callbackUrl": "https://your-callback-url.com/notify", # Optional
"chunkSize": 1000, # Optional: Override default
"includeSchema": true # Optional: Include CREATE TABLE statements
}'
Response:
{
"status": "accepted",
"progressKey": "dump_20240315-123456",
"message": "Dump process started"
}
curl --location 'https://starbasedb.YOUR-ID-HERE.workers.dev/export/dump/status/dump_20240315-123456' \
--header 'Authorization: Bearer YOUR-TOKEN'
Response:
{
"status": "processing",
"progress": {
"totalRows": 1000000,
"processedRows": 250000,
"percentComplete": 25,
"startedAt": "2024-03-15T12:34:56Z",
"estimatedCompletion": "2024-03-15T12:45:00Z"
}
}
curl --location 'https://starbasedb.YOUR-ID-HERE.workers.dev/export/dump/download/dump_20240315-123456.sql' \
--header 'Authorization: Bearer YOUR-TOKEN' \
--output database_dump.sql
When the dump completes, your callback URL will receive:
{
"status": "completed",
"dumpId": "dump_20240315-123456",
"downloadUrl": "https://starbasedb.YOUR-ID-HERE.workers.dev/export/dump/download/dump_20240315-123456.sql",
"format": "sql",
"size": 1048576,
"completedAt": "2024-03-15T12:45:00Z"
}
npm run test:dump small
npm run test:dump large
npm run test:dump breathing
Run for each format:
npm run test:dump format sql
npm run test:dump format csv
npm run test:dump format json
Test scenarios:
npm run test:dump errors
Testing Small database exports (< 30 seconds) Large database exports (> 30 seconds) Different formats (SQL, CSV, JSON) Callback notifications Error handling Resumption after interruption
Testing Done Unit tests for all components Integration tests for the full export flow Manual testing with databases of various siz
Kunal Darekar
@Kunal-Darekar
Outerbase (YC W23)
@outerbase