0xMiden / 0xMiden/note-transport-service

Migrations run implicitly per pool-connection against the live DB

オープン
#131 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
enhancement production-readiness
主要言語
Rust
スター
3
フォーク
10
平均マージ
2時間 23分
マージ済み PR(30日)
4

説明

Severity: medium.

### Summary

`apply_migrations` runs in the pool's `create()` for each of up to 16 connections (`crates/node/src/database/sqlite/connection_manager.rs:100-106`, `migrations.rs:12-22`). The `add_seq_cursor` migration is a full table rebuild (create new table, copy all rows, drop old).

### Impact

- No operator-controlled migration step: merely starting a new binary against a production file rewrites the whole table, with startup stalls proportional to DB size and no backup taken first.
- Concurrent lazy connection creation can race (`pending_migrations` is computed before the write lock), so a second connection may attempt an already-applied migration and fail connection creation.
- `migrations.rs:13` `.expect("In memory migrations never fail")` panics on any I/O error from `pending_migrations` (which reads `__diesel_schema_migrations`); deadpool catches the panic and fails the connection, but it's still a latent panic path.

### Recommendation

Run migrations exactly once at startup on a dedicated connection before building the pool; keep per-connection setup to PRAGMAs only; replace the `expect` with error propagation. Consider a `--migrate` gate and a startup log of applied versions.

---
Part of #114.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

Examine the connection manager in crates/node/src/database/sqlite/connection_manager.rs and the migration logic in migrations.rs. The issue is about moving migrations out of the pool creation and ensuring they run once at startup. Start by understanding the current flow of apply_migrations and how pending_migrations is computed. A successful fix will involve creating a dedicated migration connection, handling errors properly, and adding logging.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
sqlite
領域
backend, database
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。