indexeddb: Regularise migration method names

Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
This commit is contained in:
Andy Balaam
2024-02-05 15:21:04 +00:00
parent de9adc8d3d
commit 88d10210ad
5 changed files with 29 additions and 43 deletions

View File

@@ -49,29 +49,28 @@ pub async fn open_and_upgrade_db(
let old_version = db_version(name).await?;
if old_version < 5 {
v0_to_v5::migrate_schema_up_to_v5(name).await?;
v0_to_v5::schema_add(name).await?;
}
if old_version < 6 {
v5_to_v7::migrate_schema_up_to_v6(name).await?;
v5_to_v7::schema_add(name).await?;
}
if old_version < 7 {
v5_to_v7::prepare_data_for_v7(name, serializer).await?;
v5_to_v7::migrate_schema_for_v7(name).await?;
v5_to_v7::data_migrate(name, serializer).await?;
v5_to_v7::schema_delete(name).await?;
}
if old_version < 8 {
v7_to_v8::prepare_data_for_v8(name, serializer).await?;
v7_to_v8::migrate_schema_for_v8(name).await?;
v7_to_v8::data_migrate(name, serializer).await?;
v7_to_v8::schema_bump(name).await?;
}
if old_version < 9 {
v8_to_v10::upgrade_scheme_to_v9_create_inbound_group_sessions3(name).await?;
v8_to_v10::schema_add(name).await?;
}
if old_version < 10 {
v8_to_v10::migrate_data_before_v10_populate_inbound_group_sessions3(name, serializer)
.await?;
v8_to_v10::upgrade_scheme_to_v10_delete_inbound_group_sessions2(name).await?;
v8_to_v10::data_migrate(name, serializer).await?;
v8_to_v10::schema_delete(name).await?;
}
// Open and return the DB (we know it's at the latest version)
@@ -538,7 +537,7 @@ mod tests {
}
async fn create_v5_db(name: &str) -> std::result::Result<IdbDatabase, DomException> {
v0_to_v5::migrate_schema_up_to_v5(name).await?;
v0_to_v5::schema_add(name).await?;
IdbDatabase::open_u32(name, 5)?.await
}
}

View File

@@ -25,30 +25,30 @@ use crate::crypto_store::{
};
/// Perform schema migrations as needed, up to schema version 5.
pub(crate) async fn migrate_schema_up_to_v5(name: &str) -> Result<(), DomException> {
pub(crate) async fn schema_add(name: &str) -> Result<(), DomException> {
do_schema_upgrade(name, 5, |db, old_version| {
// An old_version of 1 could either mean actually the first version of the
// schema, or a completely empty schema that has been created with a
// call to `IdbDatabase::open` with no explicit "version". So, to determine
// if we need to create the V1 stores, we actually check if the schema is empty.
if db.object_store_names().next().is_none() {
migrate_stores_to_v1(db)?;
schema_add_v1(db)?;
}
if old_version < 2 {
migrate_stores_to_v2(db)?;
schema_add_v2(db)?;
}
if old_version < 3 {
migrate_stores_to_v3(db)?;
schema_add_v3(db)?;
}
if old_version < 4 {
migrate_stores_to_v4(db)?;
schema_add_v4(db)?;
}
if old_version < 5 {
migrate_stores_to_v5(db)?;
schema_add_v5(db)?;
}
Ok(())
@@ -56,7 +56,7 @@ pub(crate) async fn migrate_schema_up_to_v5(name: &str) -> Result<(), DomExcepti
.await
}
fn migrate_stores_to_v1(db: &IdbDatabase) -> Result<(), DomException> {
fn schema_add_v1(db: &IdbDatabase) -> Result<(), DomException> {
db.create_object_store(keys::CORE)?;
db.create_object_store(keys::SESSION)?;
@@ -72,7 +72,7 @@ fn migrate_stores_to_v1(db: &IdbDatabase) -> Result<(), DomException> {
Ok(())
}
fn migrate_stores_to_v2(db: &IdbDatabase) -> Result<(), DomException> {
fn schema_add_v2(db: &IdbDatabase) -> Result<(), DomException> {
// We changed how we store inbound group sessions, the key used to
// be a tuple of `(room_id, sender_key, session_id)` now it's a
// tuple of `(room_id, session_id)`
@@ -86,7 +86,7 @@ fn migrate_stores_to_v2(db: &IdbDatabase) -> Result<(), DomException> {
Ok(())
}
fn migrate_stores_to_v3(db: &IdbDatabase) -> Result<(), DomException> {
fn schema_add_v3(db: &IdbDatabase) -> Result<(), DomException> {
// We changed the way we store outbound session.
// ShareInfo changed from a struct to an enum with struct variant.
// Let's just discard the existing outbounds
@@ -99,12 +99,12 @@ fn migrate_stores_to_v3(db: &IdbDatabase) -> Result<(), DomException> {
Ok(())
}
fn migrate_stores_to_v4(db: &IdbDatabase) -> Result<(), DomException> {
fn schema_add_v4(db: &IdbDatabase) -> Result<(), DomException> {
db.create_object_store(keys::SECRETS_INBOX)?;
Ok(())
}
fn migrate_stores_to_v5(db: &IdbDatabase) -> Result<(), DomException> {
fn schema_add_v5(db: &IdbDatabase) -> Result<(), DomException> {
// Create a new store for outgoing secret requests
let object_store = db.create_object_store(keys::GOSSIP_REQUESTS)?;

View File

@@ -35,7 +35,7 @@ use crate::{
};
/// Perform the schema upgrade v5 to v6, creating `inbound_group_sessions2`.
pub(crate) async fn migrate_schema_up_to_v6(name: &str) -> Result<(), DomException> {
pub(crate) async fn schema_add(name: &str) -> Result<(), DomException> {
do_schema_upgrade(name, 6, |db, _| {
let object_store = db.create_object_store(old_keys::INBOUND_GROUP_SESSIONS_V2)?;
@@ -51,10 +51,7 @@ pub(crate) async fn migrate_schema_up_to_v6(name: &str) -> Result<(), DomExcepti
}
/// Migrate data from `inbound_group_sessions` into `inbound_group_sessions2`.
pub(crate) async fn prepare_data_for_v7(
name: &str,
serializer: &IndexeddbSerializer,
) -> Result<()> {
pub(crate) async fn data_migrate(name: &str, serializer: &IndexeddbSerializer) -> Result<()> {
info!("IndexeddbCryptoStore migrate data before v7 starting");
let db = IdbDatabase::open(name)?.await?;
let res = do_prepare_data_for_v7(serializer, &db).await;
@@ -119,7 +116,7 @@ async fn do_prepare_data_for_v7(serializer: &IndexeddbSerializer, db: &IdbDataba
}
/// Perform the schema upgrade v6 to v7, deleting `inbound_group_sessions`.
pub(crate) async fn migrate_schema_for_v7(name: &str) -> Result<(), DomException> {
pub(crate) async fn schema_delete(name: &str) -> Result<(), DomException> {
do_schema_upgrade(name, 7, |db, _| {
db.delete_object_store(old_keys::INBOUND_GROUP_SESSIONS_V1)?;
Ok(())

View File

@@ -33,10 +33,7 @@ use crate::{
/// `inbound_group_sessions` verbatim into `inbound_group_sessions2`. What we
/// should have done is re-hash them using the new table name, so we fix them up
/// here.
pub(crate) async fn prepare_data_for_v8(
name: &str,
serializer: &IndexeddbSerializer,
) -> Result<()> {
pub(crate) async fn data_migrate(name: &str, serializer: &IndexeddbSerializer) -> Result<()> {
info!("IndexeddbCryptoStore upgrade data -> v8 starting");
let db = IdbDatabase::open(name)?.await?;
@@ -119,7 +116,7 @@ pub(crate) async fn prepare_data_for_v8(
}
/// Perform the schema upgrade v7 to v8, Just bumping the schema version.
pub(crate) async fn migrate_schema_for_v8(name: &str) -> Result<(), DomException> {
pub(crate) async fn schema_bump(name: &str) -> Result<(), DomException> {
do_schema_upgrade(name, 8, |_, _| {
// Just bump the version number to 8 to demonstrate that we have run the data
// changes from prepare_data_for_v8.

View File

@@ -34,9 +34,7 @@ use crate::{
};
/// Perform the schema upgrade v8 to v9, creating `inbound_group_sessions3`.
pub(crate) async fn upgrade_scheme_to_v9_create_inbound_group_sessions3(
name: &str,
) -> Result<(), DomException> {
pub(crate) async fn schema_add(name: &str) -> Result<(), DomException> {
do_schema_upgrade(name, 9, |db, _| {
let object_store = db.create_object_store(keys::INBOUND_GROUP_SESSIONS_V3)?;
@@ -61,10 +59,7 @@ pub(crate) async fn upgrade_scheme_to_v9_create_inbound_group_sessions3(
}
/// Migrate data from `inbound_group_sessions2` into `inbound_group_sessions3`.
pub(crate) async fn migrate_data_before_v10_populate_inbound_group_sessions3(
name: &str,
serializer: &IndexeddbSerializer,
) -> Result<()> {
pub(crate) async fn data_migrate(name: &str, serializer: &IndexeddbSerializer) -> Result<()> {
info!("IndexeddbCryptoStore migrate data before v10 starting");
let db = IdbDatabase::open(name)?.await?;
@@ -139,9 +134,7 @@ pub(crate) async fn migrate_data_before_v10_populate_inbound_group_sessions3(
}
/// Perform the schema upgrade v8 to v10, deleting `inbound_group_sessions2`.
pub(crate) async fn upgrade_scheme_to_v10_delete_inbound_group_sessions2(
name: &str,
) -> Result<(), DomException> {
pub(crate) async fn schema_delete(name: &str) -> Result<(), DomException> {
do_schema_upgrade(name, 10, |db, _| {
db.delete_object_store(old_keys::INBOUND_GROUP_SESSIONS_V2)?;
Ok(())