Manual Transaction Wrapping vs. No Transaction: Which Guarantees Atomic Schema Migrations in expo-sqlite?
0 reputation · 09 Apr 2021, 11:27 UTC
Goal
The objective is to guarantee that a schema migration either completes fully or leaves the database unchanged, even when a migration script throws an exception partway through.
Current Constraints
Expo’s expo-sqlite exposes the native SQLite API. It does not automatically wrap migration blocks in BEGIN / COMMIT / ROLLBACK transactions. When a migration throws after applying some statements, the transaction remains open until the caller explicitly calls ROLLBACK. There is no built‑in migration helper or schema‑versioning utility, so developers must manually track versions and enforce idempotency.
Unresolved Decision
- Should the Expo SDK add a migration helper that automatically wraps migrations in a transaction and rolls back on error?
- If automatic rollback is introduced, what should the API contract look like (e.g., a dedicated
runMigrationmethod, optional transaction flags)? - Alternatively, should developers be required to wrap every migration script manually, or can the library provide a higher‑level wrapper that still requires explicit transaction boundaries?