matrix_sdk_indexeddb/crypto_store/migrations/v11_to_v12.rs
1// Copyright 2024 The Matrix.org Foundation C.I.C.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Migration code that moves from inbound_group_sessions2 to
16//! inbound_group_sessions3, shrinking the values stored in each record.
17
18use indexed_db_futures::IdbKeyPath;
19use web_sys::DomException;
20
21use crate::crypto_store::{keys, migrations::do_schema_upgrade, Result};
22
23/// Perform the schema upgrade v11 to v12, adding an index on
24/// `(curve_key, sender_data_type, session_id)` to `inbound_group_sessions3`.
25pub(crate) async fn schema_add(name: &str) -> Result<(), DomException> {
26 do_schema_upgrade(name, 12, |_, transaction, _| {
27 let object_store = transaction.object_store(keys::INBOUND_GROUP_SESSIONS_V3)?;
28
29 object_store.create_index(
30 keys::INBOUND_GROUP_SESSIONS_SENDER_KEY_INDEX,
31 &IdbKeyPath::str_sequence(&["sender_key", "sender_data_type", "session_id"]),
32 )?;
33
34 Ok(())
35 })
36 .await
37}