Skip to content

fix: use prisma wal checkpoint for sqlite cleanup#599

Merged
exKAZUu merged 9 commits intomainfrom
fix/sqlite-wal-checkpoint-via-prisma
Mar 1, 2026
Merged

fix: use prisma wal checkpoint for sqlite cleanup#599
exKAZUu merged 9 commits intomainfrom
fix/sqlite-wal-checkpoint-via-prisma

Conversation

@exKAZUu
Copy link
Copy Markdown
Member

@exKAZUu exKAZUu commented Mar 1, 2026

Summary

  • replace direct -wal/-shm deletion with prisma db execute + PRAGMA wal_checkpoint(TRUNCATE)
  • keep removing the main sqlite db file before reset to preserve existing behavior
  • add a non-mock integration test that generates WAL files and executes the cleanup command

Verification

  • yarn workspace @willbooster/wb vitest run test/scripts/prismaScripts.test.ts
  • yarn check-for-ai

Co-authored-by: WillBooster (Codex CLI) <agent@willbooster.com>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the SQLite database cleanup process by integrating Prisma's wal_checkpoint command for more robust handling of Write-Ahead Log files. This change ensures that WAL files are properly truncated before deletion, preventing potential issues, while maintaining the existing behavior of removing the main database file. The addition of a comprehensive integration test validates the new cleanup logic under realistic conditions.

Highlights

  • SQLite WAL Cleanup: Replaced direct deletion of SQLite WAL and SHM files with a Prisma command (PRAGMA wal_checkpoint(TRUNCATE)) to ensure proper truncation of the Write-Ahead Log before the main database file is removed.
  • Main Database File Removal: Main SQLite database files are still directly removed after the WAL checkpoint operation, preserving existing behavior for the primary database file.
  • Integration Testing: Added a new non-mock integration test to verify the SQLite cleanup command, including the generation of WAL files and confirmation of their truncation and subsequent file removal.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • packages/wb/src/scripts/prismaScripts.ts
    • Updated the cleanUpSqliteDbIfNeeded function to use PRISMA db execute with PRAGMA wal_checkpoint(TRUNCATE) for SQLite WAL file cleanup.
    • Removed explicit rm -f commands for WAL and SHM files, relying on the wal_checkpoint for their management.
  • packages/wb/test/scripts/prismaScripts.test.ts
    • Added a new integration test suite for prismaScripts.reset to verify SQLite WAL truncation and file removal.
    • Included helper functions to create temporary project directories, install Prisma, and set up SQLite databases with WAL mode enabled for testing.
Activity
  • The author, exKAZUu, has provided a summary of the changes and verification steps, indicating that the changes have been tested locally.
  • Verification steps include running specific Vitest tests and a check-for-ai command.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

このプルリクエストは、SQLiteのクリーンアップ処理を改善し、-wal/-shmファイルを直接削除する代わりに PRAGMA wal_checkpoint(TRUNCATE) を使用するように変更します。これにより、データベースが他のプロセスによって使用されている場合に、より安全にクリーンアップできるようになります。また、この変更を検証するための統合テストが追加されており、これも素晴らしい点です。
レビューコメントで指摘したように、エラーを無視する || true を削除することで、スクリプトの堅牢性をさらに向上させることができると考えます。

Co-authored-by: WillBooster (Codex CLI) <agent@willbooster.com>
@exKAZUu
Copy link
Copy Markdown
Member Author

exKAZUu commented Mar 1, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

このプルリクエストは、SQLiteのクリーンアップ処理を改善し、-wal / -shmファイルを直接削除する代わりに PRAGMA wal_checkpoint(TRUNCATE) を使用するように変更しています。これにより、データベース接続がアクティブな場合に発生する可能性のあるデータ損失や破損のリスクが軽減されます。また、この変更を検証するための新しい統合テストも追加されています。全体的に良い改善ですが、クリーンアップコマンドが補助ファイル(-wal、-shm)を削除しなくなっている点について、修正提案をコメントしました。

Co-authored-by: WillBooster (Codex CLI) <agent@willbooster.com>
@exKAZUu
Copy link
Copy Markdown
Member Author

exKAZUu commented Mar 1, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

このプルリクエストは、SQLiteのクリーンアップ処理を改善し、WALファイルをより安全に扱うように変更するものですね。PRAGMA wal_checkpoint(TRUNCATE) を使うアプローチは適切です。また、この変更に対する統合テストの追加も素晴らしいです。
レビューでは、テストコードの依存関係に関する重大な問題と、テストの保守性を向上させるための提案をさせていただきました。

Co-authored-by: WillBooster (Codex CLI) <agent@willbooster.com>
@exKAZUu
Copy link
Copy Markdown
Member Author

exKAZUu commented Mar 1, 2026

/gemini review

@exKAZUu
Copy link
Copy Markdown
Member Author

exKAZUu commented Mar 1, 2026

Gemini review points handled as follows:

  • removed || true from checkpoint command
  • replaced experimental node:sqlite usage with sqlite3 CLI-based WAL generation
  • exported cleanUpSqliteDbIfNeeded and updated test to call it directly
  • kept -wal/-shm direct deletion intentionally, because this PR's goal is to replace sidecar deletion with PRAGMA wal_checkpoint(TRUNCATE)

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

このプルリクエストは、SQLiteのWALファイルをクリーンアップする方法を改善するものです。直接ファイルを削除する代わりに PRAGMA wal_checkpoint(TRUNCATE)prisma db execute 経由で実行するよう変更されており、より安全で堅牢な方法になっています。また、この変更を検証するための新しい統合テストが追加されている点も素晴らしいです。

レビューコメントとして、テストコードの保守性と網羅性をさらに向上させるための提案を2点挙げました。ご確認いただければ幸いです。

Co-authored-by: WillBooster (Codex CLI) <agent@willbooster.com>
@exKAZUu
Copy link
Copy Markdown
Member Author

exKAZUu commented Mar 1, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

このプルリクエストは、SQLiteデータベースのクリーンアップ処理を改善し、WALファイルをより安全に扱うように変更するものです。直接ファイルを削除する代わりに PRAGMA wal_checkpoint(TRUNCATE) を使用するようになり、堅牢性が向上しています。

レビューでは、クリーンアップ処理をさらに改善するための提案をしました。チェックポイント実行後に、関連する -wal および -shm ファイルも明示的に削除することで、不要なファイルが残らないようにすることを推奨します。また、その変更に伴うテストコードの修正も提案しています。

@exKAZUu
Copy link
Copy Markdown
Member Author

exKAZUu commented Mar 1, 2026

Intentional decision: this PR replaces direct sidecar deletion with wal_checkpoint(TRUNCATE) (per request), so we keep avoiding explicit -wal/-shm removal in the implementation. The integration test checks WAL truncation and DB cleanup accordingly.

Co-authored-by: WillBooster (Codex CLI) <agent@willbooster.com>
@exKAZUu
Copy link
Copy Markdown
Member Author

exKAZUu commented Mar 1, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

このプルリクエストは、SQLiteのWALファイルをクリーンアップする方法を、ファイルを直接削除するのではなく PRAGMA wal_checkpoint(TRUNCATE) を使用するように変更するものです。この変更は cleanUpLitestreamdeployForce スクリプトに適用されています。また、この新しい動作を検証するための統合テストも追加されています。

コードの変更は適切であり、目的を達成しているように見えます。追加されたテストは素晴らしいですが、 -wal-shm ファイルが正しくクリーンアップされていることを完全に検証するために、アサーションを追加する改善の余地があります。

Co-authored-by: WillBooster (Codex CLI) <agent@willbooster.com>
@exKAZUu
Copy link
Copy Markdown
Member Author

exKAZUu commented Mar 1, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

このプルリクエストは、SQLiteのWALファイルをクリーンアップする方法を、直接ファイルを削除するのではなく PRAGMA wal_checkpoint(TRUNCATE) を使うように変更するものです。これはより安全で堅牢なアプローチです。また、この変更を検証するための統合テストが追加されており、素晴らしい改善です。

レビューの結果、1点修正提案があります。新しいクリーンアップコマンドでは、-wal-shm ファイルが削除されずに残ってしまう可能性があるようです。提案した修正を適用することで、これらのファイルも確実にクリーンアップされるようになります。詳細は各コメントをご確認ください。

exKAZUu and others added 2 commits March 1, 2026 18:21
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: WillBooster (Codex CLI) <agent@willbooster.com>
@exKAZUu exKAZUu enabled auto-merge (squash) March 1, 2026 09:24
@exKAZUu
Copy link
Copy Markdown
Member Author

exKAZUu commented Mar 1, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

このプルリクエストは、SQLiteのクリーンアップ処理を改善し、単純なファイル削除からPRAGMA wal_checkpoint(TRUNCATE)を使用するより安全な方法に変更するものです。これにより、WAL (Write-Ahead Logging) モードで発生しうるデータ損失のリスクを低減します。変更は論理的に正しく、新しく追加された統合テストによってその有効性が十分に検証されています。1点、コードの可読性を向上させるための提案があります。

Comment on lines +37 to 38
return `${cleanUpCommand}; PRISMA migrate reset --force --skip-seed && ${cleanUpCommand}
&& litestream restore -config litestream.yml -o ${dirPath}/prod.sqlite3 ${dirPath}/prod.sqlite3 && ls -ahl ${dirPath}/prod.sqlite3 && ALLOW_TO_SKIP_SEED=0 PRISMA migrate deploy`;
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.

medium

生成されるシェルコマンドが非常に長くなっており、可読性と保守性に課題があります。
コマンドの各部分を配列に格納し、joinメソッドで連結することで、スクリプトの各ステップが明確になり、将来の修正が容易になります。

    const commands = [
      `PRISMA migrate reset --force --skip-seed`,
      cleanUpCommand,
      `litestream restore -config litestream.yml -o ${dirPath}/prod.sqlite3 ${dirPath}/prod.sqlite3`,
      `ls -ahl ${dirPath}/prod.sqlite3`,
      'ALLOW_TO_SKIP_SEED=0 PRISMA migrate deploy',
    ];
    return `${cleanUpCommand}; ${commands.join(' && ')}`;

@exKAZUu exKAZUu merged commit 0922a7b into main Mar 1, 2026
7 checks passed
@exKAZUu exKAZUu deleted the fix/sqlite-wal-checkpoint-via-prisma branch March 1, 2026 09:27
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