diff --git a/crates/core/src/call_view.rs b/crates/core/src/call_view.rs index 49688ce..b2b4382 100644 --- a/crates/core/src/call_view.rs +++ b/crates/core/src/call_view.rs @@ -347,6 +347,7 @@ mod tests { title: None, crm_transcript_id: None, crm_base_url: None, + language: None, uploaded_at: None, } } diff --git a/crates/core/src/model.rs b/crates/core/src/model.rs index e81f702..b834950 100644 --- a/crates/core/src/model.rs +++ b/crates/core/src/model.rs @@ -48,6 +48,9 @@ pub struct Call { pub crm_base_url: Option, /// When the transcript was last uploaded. pub uploaded_at: Option>, + /// The language (ISO 639-1 code) the call is transcribed in, chosen + /// when its transcription was started; `None` before that. + pub language: Option, } /// A single transcribed word with its timing and speaker attribution. diff --git a/crates/core/src/playback.rs b/crates/core/src/playback.rs index 4a46c5b..0df2ca9 100644 --- a/crates/core/src/playback.rs +++ b/crates/core/src/playback.rs @@ -166,6 +166,7 @@ mod tests { title: None, crm_transcript_id: None, crm_base_url: None, + language: None, uploaded_at: None, } } diff --git a/crates/core/src/retention.rs b/crates/core/src/retention.rs index 18d6e6e..3d9b7e7 100644 --- a/crates/core/src/retention.rs +++ b/crates/core/src/retention.rs @@ -91,6 +91,7 @@ mod tests { title: None, crm_transcript_id: None, crm_base_url: None, + language: None, uploaded_at: None, } } diff --git a/crates/core/src/store.rs b/crates/core/src/store.rs index 6fac2ba..6a5e116 100644 --- a/crates/core/src/store.rs +++ b/crates/core/src/store.rs @@ -130,9 +130,25 @@ ALTER TABLE calls ADD COLUMN crm_base_url TEXT; UPDATE calls SET crm_base_url = 'https://test.euvinopro.eu' WHERE crm_transcript_id IS NOT NULL; "; +/// Version 5: the language a call is transcribed in, chosen per call when +/// its transcription is started. Before this version every transcription +/// used the then default German: backfilled for the calls one was started +/// for, so their corrections (`call_view`) stay as they were; a call still +/// waiting gets its language when the user decides. +const SCHEMA_V5_SQL: &str = " +ALTER TABLE calls ADD COLUMN language TEXT; +UPDATE calls SET language = 'de' WHERE status NOT IN ('recording', 'awaiting_decision'); +"; + /// Schema steps by `PRAGMA user_version`: entry `i` takes a database from /// version `i` to `i + 1`. A new database runs all of them. -const MIGRATIONS: &[&str] = &[SCHEMA_V1_SQL, SCHEMA_V2_SQL, SCHEMA_V3_SQL, SCHEMA_V4_SQL]; +const MIGRATIONS: &[&str] = &[ + SCHEMA_V1_SQL, + SCHEMA_V2_SQL, + SCHEMA_V3_SQL, + SCHEMA_V4_SQL, + SCHEMA_V5_SQL, +]; /// SQLite-backed store for calls and everything derived from them. pub struct Store { @@ -390,6 +406,16 @@ impl Store { Ok(()) } + /// Sets the language (ISO 639-1 code) the call is transcribed in. + pub fn set_language(&self, id: CallId, language: &str) -> Result<()> { + let conn = self.conn.lock().unwrap(); + conn.execute( + "UPDATE calls SET language = ?1 WHERE id = ?2", + params![language, id], + )?; + Ok(()) + } + pub fn mark_transcribed(&self, id: CallId, at: DateTime) -> Result<()> { let conn = self.conn.lock().unwrap(); conn.execute( @@ -549,9 +575,9 @@ fn ids_with_status(conn: &rusqlite::Connection, status: CallStatus) -> Result Result { let id: CallId = row.get(0)?; @@ -569,6 +595,7 @@ fn row_to_call(row: &Row) -> Result { let crm_transcript_id: Option = row.get(12)?; let uploaded_at: Option = row.get(13)?; let crm_base_url: Option = row.get(14)?; + let language: Option = row.get(15)?; Ok(Call { id, @@ -586,6 +613,7 @@ fn row_to_call(row: &Row) -> Result { crm_transcript_id, crm_base_url, uploaded_at: opt_dt_from_str(uploaded_at)?, + language, }) } @@ -715,6 +743,14 @@ CREATE TABLE speaker_merges ( const RELEASED_V3_STEP_SQL: &str = " ALTER TABLE calls ADD COLUMN crm_transcript_id TEXT; ALTER TABLE calls ADD COLUMN uploaded_at TEXT; +"; + + /// The schema of user_version 4, exactly as release 0.2.2 created it + /// (copied from `SCHEMA_V4_SQL` at `HEAD`): version 3 plus these + /// statements. + const RELEASED_V4_STEP_SQL: &str = " +ALTER TABLE calls ADD COLUMN crm_base_url TEXT; +UPDATE calls SET crm_base_url = 'https://test.euvinopro.eu' WHERE crm_transcript_id IS NOT NULL; "; fn user_version(path: &Path) -> i64 { @@ -738,7 +774,7 @@ ALTER TABLE calls ADD COLUMN uploaded_at TEXT; } #[test] - fn a_new_database_starts_at_version_4() { + fn a_new_database_starts_at_version_5() { let dir = tempfile::tempdir().unwrap(); let path = dir.path().join("calls.sqlite"); let store = Store::open(&path).unwrap(); @@ -750,7 +786,7 @@ ALTER TABLE calls ADD COLUMN uploaded_at TEXT; .unwrap(); drop(store); - assert_eq!(user_version(&path), 4); + assert_eq!(user_version(&path), 5); } #[test] @@ -807,7 +843,7 @@ ALTER TABLE calls ADD COLUMN uploaded_at TEXT; store.set_title(1, Some("Lieferung März")).unwrap(); store.set_speaker_merge(1, "remote:2", "remote:1").unwrap(); drop(store); - assert_eq!(user_version(&path), 4); + assert_eq!(user_version(&path), 5); let store = Store::open(&path).unwrap(); let call = store.get_call(1).unwrap().unwrap(); assert_eq!(call.title.as_deref(), Some("Lieferung März")); @@ -861,7 +897,7 @@ ALTER TABLE calls ADD COLUMN uploaded_at TEXT; .set_uploaded(1, "crm-1", "https://backend.example", uploaded) .unwrap(); drop(store); - assert_eq!(user_version(&path), 4); + assert_eq!(user_version(&path), 5); let store = Store::open(&path).unwrap(); let call = store.get_call(1).unwrap().unwrap(); assert_eq!(call.crm_transcript_id.as_deref(), Some("crm-1")); @@ -915,7 +951,64 @@ ALTER TABLE calls ADD COLUMN uploaded_at TEXT; assert_eq!(not_uploaded.crm_transcript_id, None); assert_eq!(not_uploaded.crm_base_url, None); - assert_eq!(user_version(&path), 4); + assert_eq!(user_version(&path), 5); + } + + #[test] + fn a_version_4_database_is_upgraded_backfilling_german_for_started_transcriptions() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("calls.sqlite"); + let started = "2026-11-05T10:14:00+01:00"; + { + let conn = rusqlite::Connection::open(&path).unwrap(); + conn.execute_batch(RELEASED_V1_SCHEMA_SQL).unwrap(); + conn.execute_batch(RELEASED_V2_STEP_SQL).unwrap(); + conn.execute_batch(RELEASED_V3_STEP_SQL).unwrap(); + conn.execute_batch(RELEASED_V4_STEP_SQL).unwrap(); + conn.execute_batch("PRAGMA user_version = 4;").unwrap(); + for (app, status) in [ + ("Microsoft Teams", "done"), + ("Zoom", "failed"), + ("MicroSIP", "awaiting_decision"), + ] { + conn.execute( + "INSERT INTO calls \ + (app, started_at, ended_at, status, interrupted, error, mic_path, out_path, transcribed_at, audio_deleted) \ + VALUES (?1, ?2, ?2, ?3, 0, NULL, '/rec/mic.wav', '/rec/out.wav', NULL, 0)", + rusqlite::params![app, started, status], + ) + .unwrap(); + } + } + + let store = Store::open(&path).unwrap(); + + // Transcriptions started before this version all used the then + // default German; a call still waiting has no language yet. + let languages: Vec<_> = (1..=3) + .map(|id| store.get_call(id).unwrap().unwrap().language) + .collect(); + assert_eq!( + languages, + [Some("de".to_string()), Some("de".to_string()), None] + ); + assert_eq!(user_version(&path), 5); + } + + #[test] + fn the_language_is_stored_per_call() { + let store = Store::open_in_memory().unwrap(); + let id = new_call(&store); + let other = new_call(&store); + assert_eq!(store.get_call(id).unwrap().unwrap().language, None); + + store.set_language(id, "fr").unwrap(); + + assert_eq!( + store.get_call(id).unwrap().unwrap().language.as_deref(), + Some("fr") + ); + assert_eq!(store.get_call(other).unwrap().unwrap().language, None); } #[test]