Add SQLite schema metadata for DB resources

This commit is contained in:
Eric Wendland 2026-05-16 21:54:49 +02:00
commit 527090fd4c
8 changed files with 119 additions and 14 deletions

View file

@ -21,4 +21,5 @@ geth-config = { path = "../geth-config" }
geth-control = { path = "../geth-control" }
geth-node = { path = "../geth-node" }
geth-store = { path = "../geth-store" }
rusqlite.workspace = true
tempfile.workspace = true

View file

@ -393,7 +393,13 @@ fn db_add_and_status_register_local_db_metadata() {
let paths = geth_config::GethPaths::from_home(home.path());
let node = geth_node::init_node(&paths).expect("init node");
let db_path = home.path().join("notes.sqlite");
std::fs::write(&db_path, b"sqlite placeholder").expect("write db");
let conn = rusqlite::Connection::open(&db_path).expect("open sqlite");
conn.execute(
"CREATE TABLE notes(id INTEGER PRIMARY KEY, body TEXT NOT NULL)",
[],
)
.expect("create notes table");
drop(conn);
let response = geth_node::handle_request(
&node,
@ -408,7 +414,9 @@ fn db_add_and_status_register_local_db_metadata() {
assert_eq!(db.name, "notes");
assert_eq!(db.sync_status, "local-only");
assert!(db.path_exists);
assert_eq!(db.size_bytes, Some(18));
assert!(db.size_bytes.unwrap_or_default() > 0);
assert!(db.schema_metadata.contains("tables=1"));
assert!(db.schema_metadata.contains("schema_hash="));
}
other => panic!("unexpected response: {other:?}"),
}
@ -424,10 +432,8 @@ fn db_add_and_status_register_local_db_metadata() {
geth_control::ControlResponse::DbStatus { db } => {
assert_eq!(db.name, "notes");
assert!(db.path.ends_with("notes.sqlite"));
assert_eq!(
db.schema_metadata,
"not-inspected-until-crsqlite-integration"
);
assert!(db.schema_metadata.contains("tables=1"));
assert!(db.schema_metadata.contains("schema_hash="));
}
other => panic!("unexpected response: {other:?}"),
}