/* 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 gatabase 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 /// [`RemoteSettingsConnectionInitializer::upgrade_from`]. pubconst VERSION: u32 = 2;
/// The current remote settings database schema. pubconst SQL: &str = r#"
CREATE TABLE IF NOT EXISTS records (
id TEXT PRIMARY KEY,
collection_url TEXT NOT NULL,
data BLOB NOT NULL);
CREATE TABLE IF NOT EXISTS attachments (
id TEXT PRIMARY KEY,
collection_url TEXT NOT NULL,
data BLOB NOT NULL);
CREATE TABLE IF NOT EXISTS collection_metadata (
collection_url TEXT PRIMARY KEY,
last_modified INTEGER, bucket TEXT, signature TEXT, x5u TEXT); "#;
/// Initializes an SQLite connection to the Remote Settings database, performing /// migrations as needed. #[derive(Default)] pubstruct RemoteSettingsConnectionInitializer;
fn upgrade_from(&self, tx: &Transaction<'_>, version: u32) -> open_database::Result<()> { match version { // Upgrade from a database created before this crate used sql-support. 0 => {
tx.execute("ALTER TABLE collection_metadata DROP column fetched", ())?;
Ok(())
} 1 => {
tx.execute("ALTER TABLE collection_metadata ADD COLUMN bucket TEXT", ())?;
tx.execute( "ALTER TABLE collection_metadata ADD COLUMN signature TEXT",
(),
)?;
tx.execute("ALTER TABLE collection_metadata ADD COLUMN x5u TEXT", ())?;
Ok(())
}
_ => Err(open_database::Error::IncompatibleVersion(version)),
}
}
}
#[cfg(test)] mod test { usesuper::*; use sql_support::open_database::test_utils::MigratedDatabaseFile;
// Snapshot of the v0 schema. We use this to test that we can migrate from there to the // current schema. const V0_SCHEMA: &str = r#"
CREATE TABLE IF NOT EXISTS records (
id TEXT PRIMARY KEY,
collection_url TEXT NOT NULL,
data BLOB NOT NULL);
CREATE TABLE IF NOT EXISTS attachments (
id TEXT PRIMARY KEY,
collection_url TEXT NOT NULL,
data BLOB NOT NULL);
CREATE TABLE IF NOT EXISTS collection_metadata (
collection_url TEXT PRIMARY KEY,
last_modified INTEGER,
fetched BOOLEAN);
PRAGMA user_version=0; "#;
/// Test running all schema upgrades from V16, which was the first schema with a "real" /// migration. /// /// If an upgrade fails, then this test will fail with a panic. #[test] fn test_all_upgrades() { let db_file = MigratedDatabaseFile::new(RemoteSettingsConnectionInitializer, V0_SCHEMA);
db_file.run_all_upgrades();
db_file.assert_schema_matches_new_database();
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.8 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.