crypto: Use a transaction to create sqlite tables.

master
Damir Jelić 2020-10-21 14:01:27 +02:00
parent dd0642cd59
commit 959e8450af
3 changed files with 22 additions and 16 deletions

View File

@ -26,6 +26,7 @@ use matrix_sdk_common_macros::async_trait;
use super::{ use super::{
caches::{DeviceStore, GroupSessionStore, SessionStore}, caches::{DeviceStore, GroupSessionStore, SessionStore},
pickle_key::EncryptedPickleKey,
Changes, CryptoStore, InboundGroupSession, ReadOnlyAccount, Result, Session, Changes, CryptoStore, InboundGroupSession, ReadOnlyAccount, Result, Session,
}; };
use crate::identities::{ReadOnlyDevice, UserIdentities}; use crate::identities::{ReadOnlyDevice, UserIdentities};

View File

@ -46,6 +46,7 @@ pub(crate) mod sqlite;
use matrix_sdk_common::identifiers::DeviceIdBox; use matrix_sdk_common::identifiers::DeviceIdBox;
pub use memorystore::MemoryStore; pub use memorystore::MemoryStore;
use pickle_key::EncryptedPickleKey;
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
#[cfg(feature = "sqlite_cryptostore")] #[cfg(feature = "sqlite_cryptostore")]
pub use sqlite::SqliteStore; pub use sqlite::SqliteStore;

View File

@ -167,7 +167,9 @@ impl SqliteStore {
async fn create_tables(&self) -> Result<()> { async fn create_tables(&self) -> Result<()> {
let mut connection = self.connection.lock().await; let mut connection = self.connection.lock().await;
connection let mut transaction = connection.begin().await?;
transaction
.execute( .execute(
r#" r#"
CREATE TABLE IF NOT EXISTS accounts ( CREATE TABLE IF NOT EXISTS accounts (
@ -183,7 +185,7 @@ impl SqliteStore {
) )
.await?; .await?;
connection transaction
.execute( .execute(
r#" r#"
CREATE TABLE IF NOT EXISTS sessions ( CREATE TABLE IF NOT EXISTS sessions (
@ -202,7 +204,7 @@ impl SqliteStore {
) )
.await?; .await?;
connection transaction
.execute( .execute(
r#" r#"
CREATE TABLE IF NOT EXISTS tracked_users ( CREATE TABLE IF NOT EXISTS tracked_users (
@ -220,7 +222,7 @@ impl SqliteStore {
) )
.await?; .await?;
connection transaction
.execute( .execute(
r#" r#"
CREATE TABLE IF NOT EXISTS inbound_group_sessions ( CREATE TABLE IF NOT EXISTS inbound_group_sessions (
@ -241,7 +243,7 @@ impl SqliteStore {
) )
.await?; .await?;
connection transaction
.execute( .execute(
r#" r#"
CREATE TABLE IF NOT EXISTS group_session_claimed_keys ( CREATE TABLE IF NOT EXISTS group_session_claimed_keys (
@ -259,7 +261,7 @@ impl SqliteStore {
) )
.await?; .await?;
connection transaction
.execute( .execute(
r#" r#"
CREATE TABLE IF NOT EXISTS group_session_chains ( CREATE TABLE IF NOT EXISTS group_session_chains (
@ -276,7 +278,7 @@ impl SqliteStore {
) )
.await?; .await?;
connection transaction
.execute( .execute(
r#" r#"
CREATE TABLE IF NOT EXISTS devices ( CREATE TABLE IF NOT EXISTS devices (
@ -296,7 +298,7 @@ impl SqliteStore {
) )
.await?; .await?;
connection transaction
.execute( .execute(
r#" r#"
CREATE TABLE IF NOT EXISTS algorithms ( CREATE TABLE IF NOT EXISTS algorithms (
@ -313,7 +315,7 @@ impl SqliteStore {
) )
.await?; .await?;
connection transaction
.execute( .execute(
r#" r#"
CREATE TABLE IF NOT EXISTS device_keys ( CREATE TABLE IF NOT EXISTS device_keys (
@ -331,7 +333,7 @@ impl SqliteStore {
) )
.await?; .await?;
connection transaction
.execute( .execute(
r#" r#"
CREATE TABLE IF NOT EXISTS device_signatures ( CREATE TABLE IF NOT EXISTS device_signatures (
@ -350,7 +352,7 @@ impl SqliteStore {
) )
.await?; .await?;
connection transaction
.execute( .execute(
r#" r#"
CREATE TABLE IF NOT EXISTS users ( CREATE TABLE IF NOT EXISTS users (
@ -367,7 +369,7 @@ impl SqliteStore {
) )
.await?; .await?;
connection transaction
.execute( .execute(
r#" r#"
CREATE TABLE IF NOT EXISTS users_trust_state ( CREATE TABLE IF NOT EXISTS users_trust_state (
@ -382,7 +384,7 @@ impl SqliteStore {
) )
.await?; .await?;
connection transaction
.execute( .execute(
r#" r#"
CREATE TABLE IF NOT EXISTS cross_signing_keys ( CREATE TABLE IF NOT EXISTS cross_signing_keys (
@ -399,7 +401,7 @@ impl SqliteStore {
) )
.await?; .await?;
connection transaction
.execute( .execute(
r#" r#"
CREATE TABLE IF NOT EXISTS user_keys ( CREATE TABLE IF NOT EXISTS user_keys (
@ -416,7 +418,7 @@ impl SqliteStore {
) )
.await?; .await?;
connection transaction
.execute( .execute(
r#" r#"
CREATE TABLE IF NOT EXISTS user_key_signatures ( CREATE TABLE IF NOT EXISTS user_key_signatures (
@ -435,7 +437,7 @@ impl SqliteStore {
) )
.await?; .await?;
connection transaction
.execute( .execute(
r#" r#"
CREATE TABLE IF NOT EXISTS key_value ( CREATE TABLE IF NOT EXISTS key_value (
@ -453,6 +455,8 @@ impl SqliteStore {
) )
.await?; .await?;
transaction.commit().await?;
Ok(()) Ok(())
} }