CREATE TABLE IF NOT EXISTS crack_search_contexts ( id INTEGER PRIMARY KEY AUTOINCREMENT, token_hash TEXT NOT NULL UNIQUE, criteria_json TEXT NOT NULL, matched_access_point_count INTEGER NOT NULL, handshake_count INTEGER NOT NULL, created_at TEXT NOT NULL, expires_at TEXT NOT NULL, CHECK (matched_access_point_count >= 0), CHECK (handshake_count >= 0), CHECK (expires_at > created_at) ); CREATE TABLE IF NOT EXISTS crack_search_context_handshakes ( token_hash TEXT NOT NULL, handshake_id INTEGER NOT NULL, PRIMARY KEY (token_hash, handshake_id), FOREIGN KEY (token_hash) REFERENCES crack_search_contexts(token_hash) ON DELETE CASCADE, FOREIGN KEY (handshake_id) REFERENCES handshakes(id) ON DELETE CASCADE ); CREATE INDEX IF NOT EXISTS idx_crack_search_contexts_expires ON crack_search_contexts(expires_at); CREATE INDEX IF NOT EXISTS idx_crack_search_context_handshakes_handshake ON crack_search_context_handshakes(handshake_id);