refactor(kon): clean up storage and cloud-providers — remove unused deps, add safety docs
- Remove unused chrono and uuid dependencies from kon-storage - Add schema versioning TODO to run_migrations() for pre-release safety - Add doc comment and usage example to log_error() (uncalled public API) - Add TODO to consolidate app_data_dir() with model_manager::dirs_path() - Add safety comments and #[allow(deprecated)] to keystore set_var usage - Add TODO for keyring crate migration in cloud-providers keystore - Apply cargo fmt Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,11 @@ pub async fn init(db_path: &Path) -> Result<SqlitePool> {
|
||||
}
|
||||
|
||||
/// Run schema migrations.
|
||||
///
|
||||
/// TODO(pre-release): Implement schema versioning for safe upgrades.
|
||||
/// Currently uses `CREATE TABLE IF NOT EXISTS` which silently ignores column
|
||||
/// additions/removals. Before shipping, add a `schema_version` table and
|
||||
/// sequential migration steps so existing user databases upgrade cleanly.
|
||||
async fn run_migrations(pool: &SqlitePool) -> Result<()> {
|
||||
sqlx::query(
|
||||
"CREATE TABLE IF NOT EXISTS transcripts (
|
||||
@@ -186,10 +191,7 @@ pub async fn insert_transcript(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_transcript(
|
||||
pool: &SqlitePool,
|
||||
id: &str,
|
||||
) -> Result<Option<TranscriptRow>> {
|
||||
pub async fn get_transcript(pool: &SqlitePool, id: &str) -> Result<Option<TranscriptRow>> {
|
||||
let row = sqlx::query(
|
||||
"SELECT id, text, source, title, audio_path, duration, engine, model_id, inference_ms, sample_rate, audio_channels, format_mode, remove_fillers, british_english, anti_hallucination, created_at FROM transcripts WHERE id = ?",
|
||||
)
|
||||
@@ -231,16 +233,14 @@ pub async fn insert_task(
|
||||
bucket: &str,
|
||||
source_transcript_id: Option<&str>,
|
||||
) -> Result<()> {
|
||||
sqlx::query(
|
||||
"INSERT INTO tasks (id, text, bucket, source_transcript_id) VALUES (?, ?, ?, ?)",
|
||||
)
|
||||
.bind(id)
|
||||
.bind(text)
|
||||
.bind(bucket)
|
||||
.bind(source_transcript_id)
|
||||
.execute(pool)
|
||||
.await
|
||||
.map_err(|e| KonError::StorageError(format!("Insert task failed: {e}")))?;
|
||||
sqlx::query("INSERT INTO tasks (id, text, bucket, source_transcript_id) VALUES (?, ?, ?, ?)")
|
||||
.bind(id)
|
||||
.bind(text)
|
||||
.bind(bucket)
|
||||
.bind(source_transcript_id)
|
||||
.execute(pool)
|
||||
.await
|
||||
.map_err(|e| KonError::StorageError(format!("Insert task failed: {e}")))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -364,7 +364,19 @@ fn transcript_row_from(r: &sqlx::sqlite::SqliteRow) -> TranscriptRow {
|
||||
|
||||
// --- Error Logging ---
|
||||
|
||||
/// Log a structured error to the error_log table.
|
||||
/// Log a structured error to the `error_log` table.
|
||||
///
|
||||
/// Available for Tauri command handlers to persist errors for diagnostics.
|
||||
/// Each entry records context (which subsystem), an optional error code,
|
||||
/// the human-readable message, and optional JSON metadata.
|
||||
///
|
||||
/// # Example
|
||||
/// ```ignore
|
||||
/// log_error(&pool, "transcription", Some("WHISPER_INIT"), "Model load failed", None).await?;
|
||||
/// ```
|
||||
///
|
||||
/// TODO: Wire this into Tauri command error paths so runtime failures are
|
||||
/// persisted for user-facing error history and crash diagnostics.
|
||||
pub async fn log_error(
|
||||
pool: &SqlitePool,
|
||||
context: &str,
|
||||
|
||||
Reference in New Issue
Block a user