From 3c37eed3ef2ff46a1b72c0a993f0731cbb04ab6d Mon Sep 17 00:00:00 2001 From: Heng-Yi Wu <2316687+henry40408@users.noreply.github.com> Date: Sat, 12 Sep 2026 20:36:32 +0800 Subject: [PATCH] bisect: schema and migration half only --- src/db.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/db.rs b/src/db.rs index 94dabce..6adabe2 100644 --- a/src/db.rs +++ b/src/db.rs @@ -418,7 +418,8 @@ impl Database { upstream TEXT, doh_token TEXT, result TEXT, - authenticated_data INTEGER NOT NULL DEFAULT 0 + authenticated_data INTEGER NOT NULL DEFAULT 0, + has_result INTEGER GENERATED ALWAYS AS (result IS NOT NULL AND result != '') VIRTUAL ); CREATE INDEX IF NOT EXISTS idx_query_logs_timestamp ON query_logs(timestamp); CREATE INDEX IF NOT EXISTS idx_query_logs_domain_ts ON query_logs(domain, timestamp); @@ -642,7 +643,22 @@ impl Database { )?; } - const LATEST_VERSION: i64 = 11; + if version < 12 { + add_column_if_missing( + conn, + "query_logs", + "has_result", + "INTEGER GENERATED ALWAYS AS (result IS NOT NULL AND result != '') VIRTUAL", + )?; + conn.execute_batch( + "DROP INDEX IF EXISTS idx_query_logs_ts_metrics; + CREATE INDEX idx_query_logs_ts_metrics \ + ON query_logs(timestamp, blocked, cached, response_ms, query_type, has_result); + ANALYZE;", + )?; + } + + const LATEST_VERSION: i64 = 12; if version < LATEST_VERSION { conn.pragma_update(None, "user_version", LATEST_VERSION)?; } @@ -2297,7 +2313,7 @@ fn add_column_if_missing( ) -> Result<(), rusqlite::Error> { let exists: bool = conn .query_row( - &format!("SELECT COUNT(*) FROM pragma_table_info('{table}') WHERE name = ?1"), + &format!("SELECT COUNT(*) FROM pragma_table_xinfo('{table}') WHERE name = ?1"), params![column], |row| row.get::<_, i64>(0), )