mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-27 13:04:20 +01:00
add sqlite integrity check back
This commit is contained in:
@@ -15,6 +15,7 @@ use std::any::Any;
|
||||
use std::backtrace::Backtrace;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::{IsTerminal, Write};
|
||||
use std::path::Path;
|
||||
use std::sync::{mpsc, Arc, Mutex};
|
||||
use tracing_subscriber::field::MakeExt;
|
||||
use tracing_subscriber::fmt::format;
|
||||
@@ -598,13 +599,23 @@ fn run_simulation_default(
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let result = execute_plans(env.clone(), plans, &mut states, last_execution);
|
||||
let mut result = execute_plans(env.clone(), plans, &mut states, last_execution);
|
||||
|
||||
let env = env.lock().unwrap();
|
||||
env.io.print_stats();
|
||||
|
||||
tracing::info!("Simulation completed");
|
||||
|
||||
if result.error.is_none() {
|
||||
let ic = integrity_check(&env.get_db_path());
|
||||
if let Err(err) = ic {
|
||||
tracing::error!("integrity check failed: {}", err);
|
||||
result.error = Some(turso_core::LimboError::InternalError(err.to_string()));
|
||||
} else {
|
||||
tracing::info!("integrity check passed");
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
@@ -667,3 +678,23 @@ const BANNER: &str = r#"
|
||||
\____________________________/
|
||||
|
||||
"#;
|
||||
|
||||
fn integrity_check(db_path: &Path) -> anyhow::Result<()> {
|
||||
let conn = rusqlite::Connection::open(db_path)?;
|
||||
let mut stmt = conn.prepare("SELECT * FROM pragma_integrity_check;")?;
|
||||
let mut rows = stmt.query(())?;
|
||||
let mut result: Vec<String> = Vec::new();
|
||||
|
||||
while let Some(row) = rows.next()? {
|
||||
result.push(row.get(0)?);
|
||||
}
|
||||
if result.is_empty() {
|
||||
anyhow::bail!("simulation failed: integrity_check should return `ok` or a list of problems")
|
||||
}
|
||||
if !result[0].eq_ignore_ascii_case("ok") {
|
||||
// Build a list of problems
|
||||
result.iter_mut().for_each(|row| *row = format!("- {row}"));
|
||||
anyhow::bail!("simulation failed: {}", result.join("\n"))
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use sql_generation::generation::pick_index;
|
||||
|
||||
use crate::{
|
||||
generation::plan::{Interaction, InteractionPlanState},
|
||||
integrity_check,
|
||||
runner::execution::ExecutionContinuation,
|
||||
};
|
||||
|
||||
@@ -25,13 +26,23 @@ pub(crate) fn run_simulation(
|
||||
secondary_pointer: 0,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let result = execute_plans(env.clone(), plans, &mut states, last_execution);
|
||||
let mut result = execute_plans(env.clone(), plans, &mut states, last_execution);
|
||||
|
||||
let env = env.lock().unwrap();
|
||||
env.io.print_stats();
|
||||
|
||||
tracing::info!("Simulation completed");
|
||||
|
||||
if result.error.is_none() {
|
||||
let ic = integrity_check(&env.get_db_path());
|
||||
if let Err(err) = ic {
|
||||
tracing::error!("integrity check failed: {}", err);
|
||||
result.error = Some(turso_core::LimboError::InternalError(err.to_string()));
|
||||
} else {
|
||||
tracing::info!("integrity check passed");
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user