fix: remove stale WAL/SHM files before pulling new databases#210
Conversation
After backup, old -wal/-shm journal files were not removed before extracting the new tar archive. SQLite would then try to apply the stale WAL to the freshly pulled DB, causing "database disk image is malformed" errors. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughops/commands/pull-db.ts に事前クリーンアップ手順を追加し、 Changes
sequenceDiagram
autonumber
actor Operator
participant CLI as "ops/commands/pull-db.ts"
participant DataDir as "ops/lib/data-dir.ts\nremoveAllDbFiles()"
participant FS as "Filesystem (DATA_DIR)"
participant Remote as "Remote Backup/Storage"
Operator->>CLI: pull-db 実行
CLI->>DataDir: removeAllDbFiles()
DataDir->>FS: scan & delete (*.db, *-wal, *-shm)
FS-->>DataDir: 削除結果 (count)
DataDir-->>CLI: 削除数を返す
CLI->>Remote: 既存バックアップの確認/取得
Remote-->>CLI: バックアップ転送
CLI->>FS: 圧縮展開 & sanitizeExportSettings(DATA_DIR/fullpath)
CLI-->>Operator: 完了ログ/結果
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
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 |
…restore-db Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ops/commands/pull-db.ts (1)
148-154: LGTM! WAL/SHMファイルのクリーンアップは適切に実装されています。実装は正しく、PRの目的(stale WAL journalによるDBの破損防止)を達成しています。
isDbFileプレディケートは.db、.db-wal、.db-shmを正しくマッチし、バックアップ後・プル前の適切なタイミングで削除されています。オプションの提案:削除したファイル数をログに出力すると、デバッグ時に役立つかもしれません。
🔧 削除ログを追加する場合
// Step 1.5: Remove old DB files (including -wal/-shm) to prevent // stale WAL journals from corrupting newly pulled databases const oldDbFiles = fs.readdirSync(DATA_DIR).filter(isDbFile) for (const file of oldDbFiles) { fs.unlinkSync(path.join(DATA_DIR, file)) } + if (oldDbFiles.length > 0) { + consola.info(`Removed ${oldDbFiles.length} old database file(s)`) + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ops/commands/pull-db.ts` around lines 148 - 154, Add a debug/info log after removing old DB files to report how many files were deleted: after computing oldDbFiles (the array filtered by isDbFile against DATA_DIR) and performing the fs.unlinkSync removal loop, call the repository/process logger to emit a message including oldDbFiles.length and optionally list the filenames; reference oldDbFiles, isDbFile, DATA_DIR, and the existing unlink loop so the log is placed immediately after the deletions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@ops/commands/pull-db.ts`:
- Around line 148-154: Add a debug/info log after removing old DB files to
report how many files were deleted: after computing oldDbFiles (the array
filtered by isDbFile against DATA_DIR) and performing the fs.unlinkSync removal
loop, call the repository/process logger to emit a message including
oldDbFiles.length and optionally list the filenames; reference oldDbFiles,
isDbFile, DATA_DIR, and the existing unlink loop so the log is placed
immediately after the deletions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 27792f12-c843-4302-8435-bafb05a662f6
📒 Files selected for processing (1)
ops/commands/pull-db.ts
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Summary
ops pull-dbでDBを取得した後、古い-wal/-shmジャーナルファイルが残っていると、新しいDBに適用されて "database disk image is malformed" エラーが発生する問題を修正Test plan
pnpm ops pull-db -- --app <app>で正常にDBが取得できること-wal/-shmファイルが残らないこと🤖 Generated with Claude Code
Summary by CodeRabbit