0xMiden / 0xMiden/note-transport-service

Migrations run implicitly per pool-connection against the live DB

Ouverte
#131 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
enhancement production-readiness
Langage dominant
Rust
Étoiles
3
Forks
10
Merge moyen
2 h 23 min
PR mergées (30 j)
4

Description

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.

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
sqlite
Domaine
backend, database
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Calme
Clarté
Clairement spécifiée
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.