indexeddb: Initialize DB version to zero. (#38819)

None of our automated tests were executing the initial DB setup code
because the requested version always matched.

Testing: Existing WPT coverage.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2025-08-21 18:49:57 -04:00 committed by GitHub
parent bce9f06cf8
commit 18230e9630
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
47 changed files with 303 additions and 212 deletions

View file

@ -83,7 +83,6 @@ impl SqliteEngine {
pub fn new(
base_dir: &Path,
db_info: &IndexedDBDescription,
version: u64,
pool: Arc<CoreResourceThreadPool>,
) -> Result<Self, Error> {
let mut db_path = PathBuf::new();
@ -96,7 +95,7 @@ impl SqliteEngine {
std::fs::create_dir_all(db_parent).unwrap();
std::fs::File::create(&db_path).unwrap();
}
let connection = Self::init_db(&db_path, db_info, version)?;
let connection = Self::init_db(&db_path, db_info)?;
for stmt in DB_PRAGMAS {
// TODO: Handle errors properly
@ -111,11 +110,7 @@ impl SqliteEngine {
})
}
fn init_db(
path: &Path,
db_info: &IndexedDBDescription,
version: u64,
) -> Result<Connection, Error> {
fn init_db(path: &Path, db_info: &IndexedDBDescription) -> Result<Connection, Error> {
let connection = Connection::open(path)?;
if connection.table_exists(None, "database")? {
// Database already exists, no need to initialize
@ -127,12 +122,13 @@ impl SqliteEngine {
let _ = connection.execute(stmt, ());
}
create::create_tables(&connection)?;
// From https://w3c.github.io/IndexedDB/#database-version:
// "When a database is first created, its version is 0 (zero)."
connection.execute(
"INSERT INTO database (name, origin, version) VALUES (?, ?, ?)",
"INSERT INTO database (name, origin, version) VALUES (?, ?, 0)",
params![
db_info.name.to_owned(),
db_info.origin.to_owned().ascii_serialization(),
i64::from_ne_bytes(version.to_ne_bytes())
],
)?;
Ok(connection)

View file

@ -308,7 +308,6 @@ impl IndexedDBManager {
SqliteEngine::new(
idb_base_dir,
&idb_description,
version,
self.thread_pool.clone(),
)
.expect("Failed to create sqlite engine"),