/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis *file,Youcanobtainoneathttp://mozilla.org/MPL/2.0/.
*/
use rusqlite::{Connection, Transaction}; use sql_support::open_database::{self, ConnectionInitializer};
/// The current database schema version. /// /// For any changes to the schema [`SQL`], please make sure to: /// /// 1. Bump this version. /// 2. Add a migration from the old version to the new version in /// [`RelevancyConnectionInitializer::upgrade_from`]. pubconst VERSION: u32 = 15;
/// The current database schema. pubconst SQL: &str = "
CREATE TABLE url_interest(
url_hash BLOB NOT NULL,
interest_code INTEGER NOT NULL,
PRIMARY KEY (url_hash, interest_code)
) WITHOUT ROWID;
-- Stores user interest vectors. The `kind` field stores the raw code from the `InterestVectorKind` enum.
CREATE TABLE user_interest(
kind INTEGER NOT NULL,
interest_code INTEGER NOT NULL,
count INTEGER NOT NULL,
PRIMARY KEY (kind, interest_code)
) WITHOUT ROWID;
CREATE TABLE multi_armed_bandit(
bandit TEXT NOT NULL,
arm TEXT NOT NULL,
alpha INTEGER NOT NULL,
beta INTEGER NOT NULL,
clicks INTEGER NOT NULL,
impressions INTEGER NOT NULL,
PRIMARY KEY (bandit, arm)
) WITHOUT ROWID; ";
/// Initializes an SQLite connection to the Relevancy database, performing /// migrations as needed. pubstruct RelevancyConnectionInitializer;
fn upgrade_from(&self, tx: &Transaction<'_>, version: u32) -> open_database::Result<()> { match version { // Upgrades 1-12 are missing because we started with version 13, because of a // copy-and-paste error. 13 => {
tx.execute( "
CREATE TABLE user_interest(
kind INTEGER NOT NULL,
interest_code INTEGER NOT NULL,
count INTEGER NOT NULL,
PRIMARY KEY (kind, interest_code)
) WITHOUT ROWID; ",
(),
)?;
Ok(())
} 14 => {
tx.execute( "CREATE TABLE multi_armed_bandit(
bandit TEXT NOT NULL,
arm TEXT NOT NULL,
alpha INTEGER NOT NULL,
beta INTEGER NOT NULL,
clicks INTEGER NOT NULL,
impressions INTEGER NOT NULL,
PRIMARY KEY (bandit, arm)
) WITHOUT ROWID;",
(),
)?;
Ok(())
}
_ => Err(open_database::Error::IncompatibleVersion(version)),
}
}
}
#[cfg(test)] mod test { usesuper::*; use sql_support::open_database::test_utils::MigratedDatabaseFile;
/// The first database schema we used pubconst V1_SCHEMA: &str = "
CREATE TABLE url_interest(
url_hash BLOB NOT NULL,
interest_code INTEGER NOT NULL,
PRIMARY KEY (url_hash, interest_code)
) WITHOUT ROWID;
PRAGMA user_version=13; ";
/// Test running all schema upgrades /// /// If an upgrade fails, then this test will fail with a panic. #[test] fn test_all_upgrades() { let db_file = MigratedDatabaseFile::new(RelevancyConnectionInitializer, V1_SCHEMA);
db_file.run_all_upgrades();
db_file.assert_schema_matches_new_database();
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet am 2026-06-19)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.