From 49df948de25d28601469e9ca993f33530989ebd0 Mon Sep 17 00:00:00 2001 From: salmonik Date: Thu, 29 Oct 2026 22:55:49 +0100 Subject: v3.0.0: cursor-driven roulette felt with splits and corners; drop schema migrations; require 80x24 --- src/client/database.rs | 41 ----------------------------------------- 1 file changed, 41 deletions(-) (limited to 'src/client/database.rs') diff --git a/src/client/database.rs b/src/client/database.rs index 04a271a..c4601b5 100644 --- a/src/client/database.rs +++ b/src/client/database.rs @@ -20,14 +20,9 @@ pub fn init_db(conn: &Connection) { [], ) .unwrap(); - // Migration for databases created before TOFU trust. - let _ = conn.execute("ALTER TABLE hosts ADD COLUMN fingerprint TEXT", []); // Credentials belong to a server identity (the certificate key), not to a // single address, so every address that presents the same key shares them. - if has_column(conn, "credentials", "host") { - migrate_credentials_to_fingerprints(conn); - } conn.execute( "CREATE TABLE IF NOT EXISTS credentials ( fingerprint TEXT PRIMARY KEY, @@ -39,42 +34,6 @@ pub fn init_db(conn: &Connection) { .unwrap(); } -fn has_column(conn: &Connection, table: &str, column: &str) -> bool { - let Ok(mut statement) = conn.prepare(&format!("PRAGMA table_info({table})")) else { - return false; - }; - let Ok(rows) = statement.query_map([], |row| row.get::<_, String>(1)) else { - return false; - }; - rows.flatten().any(|name| name == column) -} - -/// Re-key host-bound credentials by the fingerprint of their host. -/// -/// Rows whose host was already forgotten have no identity to attach to and are -/// dropped; those addresses have to re-authenticate once. -fn migrate_credentials_to_fingerprints(conn: &Connection) { - let tx = conn.unchecked_transaction().unwrap(); - tx.execute_batch( - "DROP TABLE IF EXISTS credentials_by_identity; - CREATE TABLE credentials_by_identity ( - fingerprint TEXT PRIMARY KEY, - username TEXT NOT NULL, - password TEXT NOT NULL - ); - INSERT OR REPLACE INTO credentials_by_identity (fingerprint, username, password) - SELECT h.fingerprint, c.username, c.password - FROM credentials c - JOIN hosts h ON h.host = c.host - WHERE h.fingerprint IS NOT NULL - ORDER BY h.last_used ASC, h.host ASC; - DROP TABLE credentials; - ALTER TABLE credentials_by_identity RENAME TO credentials;", - ) - .unwrap(); - tx.commit().unwrap(); -} - pub fn get_last_host(conn: &Connection) -> Option { let mut stmt = conn .prepare("SELECT host FROM hosts ORDER BY last_used DESC LIMIT 1") -- cgit v1.2.3