diff --git a/src/core/db.rs b/src/core/db.rs index 1a0083d..59086db 100644 --- a/src/core/db.rs +++ b/src/core/db.rs @@ -143,6 +143,20 @@ pub fn run_migrations(conn: &Connection) -> Result<()> { match conn.execute_batch(sql) { Ok(()) => { + // Framework-managed version bookkeeping: ensures the version is + // always recorded even if a migration .sql omits the INSERT. + // Uses OR REPLACE so legacy migrations that self-register are harmless. + conn.execute( + "INSERT OR REPLACE INTO schema_version (version, applied_at, description) \ + VALUES (?1, strftime('%s', 'now') * 1000, ?2)", + rusqlite::params![version, version_str], + ) + .map_err(|e| LoreError::MigrationFailed { + version, + message: format!("Failed to record schema version: {e}"), + source: Some(e), + })?; + conn.execute_batch(&format!("RELEASE {}", savepoint_name)) .map_err(|e| LoreError::MigrationFailed { version,