diff --git a/crates/matrix-sdk-sqlite/migrations/event_cache_store/011_empty_event_cache.sql b/crates/matrix-sdk-sqlite/migrations/event_cache_store/011_empty_event_cache.sql new file mode 100644 index 000000000..4b0b96f1d --- /dev/null +++ b/crates/matrix-sdk-sqlite/migrations/event_cache_store/011_empty_event_cache.sql @@ -0,0 +1,12 @@ +-- After the merge of https://github.com/matrix-org/matrix-rust-sdk/pull/5648, +-- we want all events to get a `TimelineEvent::timestamp` value (extracted from +-- `origin_server_ts`). +-- +-- To accomplish that, we are emptying the event cache. New synced events will +-- be built correctly, with a valid `TimelineEvent::timestamp`, allowing a +-- clear, stable situation. + +DELETE from linked_chunks; +DELETE from event_chunks; -- should be done by cascading +DELETE from gap_chunks; -- should be done by cascading +DELETE from events; diff --git a/crates/matrix-sdk-sqlite/src/event_cache_store.rs b/crates/matrix-sdk-sqlite/src/event_cache_store.rs index 9e753b4ae..7ea812b0a 100644 --- a/crates/matrix-sdk-sqlite/src/event_cache_store.rs +++ b/crates/matrix-sdk-sqlite/src/event_cache_store.rs @@ -63,7 +63,7 @@ const DATABASE_NAME: &str = "matrix-sdk-event-cache.sqlite3"; /// This is used to figure whether the SQLite database requires a migration. /// Every new SQL migration should imply a bump of this number, and changes in /// the [`run_migrations`] function. -const DATABASE_VERSION: u8 = 10; +const DATABASE_VERSION: u8 = 11; /// The string used to identify a chunk of type events, in the `type` field in /// the database. @@ -453,6 +453,16 @@ async fn run_migrations(conn: &SqliteAsyncConn, version: u8) -> Result<()> { } } + if version < 11 { + conn.with_transaction(|txn| { + txn.execute_batch(include_str!( + "../migrations/event_cache_store/011_empty_event_cache.sql" + ))?; + txn.set_db_version(11) + }) + .await?; + } + Ok(()) }