bump db version to 17, cleanup, rerun old migrations for users who downgraded
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
16b07ae3ec
commit
f761d4d5c9
2 changed files with 14 additions and 21 deletions
|
@ -69,9 +69,8 @@ impl Data {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn bump_database_version(&self, new_version: u64) -> Result<()> {
|
pub fn bump_database_version(&self, new_version: u64) {
|
||||||
self.global.raw_put(b"version", new_version);
|
self.global.raw_put(b"version", new_version);
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -27,15 +27,7 @@ use crate::{media, Services};
|
||||||
/// - If database is opened at lesser version we apply migrations up to this.
|
/// - If database is opened at lesser version we apply migrations up to this.
|
||||||
/// Note that named-feature migrations may also be performed when opening at
|
/// Note that named-feature migrations may also be performed when opening at
|
||||||
/// equal or lesser version. These are expected to be backward-compatible.
|
/// equal or lesser version. These are expected to be backward-compatible.
|
||||||
pub(crate) const DATABASE_VERSION: u64 = 13;
|
pub(crate) const DATABASE_VERSION: u64 = 17;
|
||||||
|
|
||||||
/// Conduit's database version.
|
|
||||||
///
|
|
||||||
/// Conduit bumped the database version to 16, but did not introduce any
|
|
||||||
/// breaking changes. Their database migrations are extremely fragile and risky,
|
|
||||||
/// and also do not really apply to us, so just to retain Conduit -> conduwuit
|
|
||||||
/// compatibility we'll check for both versions.
|
|
||||||
pub(crate) const CONDUIT_DATABASE_VERSION: u64 = 16;
|
|
||||||
|
|
||||||
pub(crate) async fn migrations(services: &Services) -> Result<()> {
|
pub(crate) async fn migrations(services: &Services) -> Result<()> {
|
||||||
let users_count = services.users.count().await;
|
let users_count = services.users.count().await;
|
||||||
|
@ -63,10 +55,7 @@ pub(crate) async fn migrations(services: &Services) -> Result<()> {
|
||||||
async fn fresh(services: &Services) -> Result<()> {
|
async fn fresh(services: &Services) -> Result<()> {
|
||||||
let db = &services.db;
|
let db = &services.db;
|
||||||
|
|
||||||
services
|
services.globals.db.bump_database_version(DATABASE_VERSION);
|
||||||
.globals
|
|
||||||
.db
|
|
||||||
.bump_database_version(DATABASE_VERSION)?;
|
|
||||||
|
|
||||||
db["global"].insert(b"feat_sha256_media", []);
|
db["global"].insert(b"feat_sha256_media", []);
|
||||||
db["global"].insert(b"fix_bad_double_separator_in_state_cache", []);
|
db["global"].insert(b"fix_bad_double_separator_in_state_cache", []);
|
||||||
|
@ -130,6 +119,7 @@ async fn migrate(services: &Services) -> Result<()> {
|
||||||
.get(b"fix_referencedevents_missing_sep")
|
.get(b"fix_referencedevents_missing_sep")
|
||||||
.await
|
.await
|
||||||
.is_not_found()
|
.is_not_found()
|
||||||
|
|| services.globals.db.database_version().await < 17
|
||||||
{
|
{
|
||||||
fix_referencedevents_missing_sep(services).await?;
|
fix_referencedevents_missing_sep(services).await?;
|
||||||
}
|
}
|
||||||
|
@ -138,15 +128,19 @@ async fn migrate(services: &Services) -> Result<()> {
|
||||||
.get(b"fix_readreceiptid_readreceipt_duplicates")
|
.get(b"fix_readreceiptid_readreceipt_duplicates")
|
||||||
.await
|
.await
|
||||||
.is_not_found()
|
.is_not_found()
|
||||||
|
|| services.globals.db.database_version().await < 17
|
||||||
{
|
{
|
||||||
fix_readreceiptid_readreceipt_duplicates(services).await?;
|
fix_readreceiptid_readreceipt_duplicates(services).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let version_match = services.globals.db.database_version().await == DATABASE_VERSION
|
if services.globals.db.database_version().await < 17 {
|
||||||
|| services.globals.db.database_version().await == CONDUIT_DATABASE_VERSION;
|
services.globals.db.bump_database_version(17);
|
||||||
|
info!("Migration: Bumped database version to 17");
|
||||||
|
}
|
||||||
|
|
||||||
assert!(
|
assert_eq!(
|
||||||
version_match,
|
services.globals.db.database_version().await,
|
||||||
|
DATABASE_VERSION,
|
||||||
"Failed asserting local database version {} is equal to known latest conduwuit database \
|
"Failed asserting local database version {} is equal to known latest conduwuit database \
|
||||||
version {}",
|
version {}",
|
||||||
services.globals.db.database_version().await,
|
services.globals.db.database_version().await,
|
||||||
|
@ -290,7 +284,7 @@ async fn db_lt_12(services: &Services) -> Result<()> {
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
services.globals.db.bump_database_version(12)?;
|
services.globals.db.bump_database_version(12);
|
||||||
info!("Migration: 11 -> 12 finished");
|
info!("Migration: 11 -> 12 finished");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -335,7 +329,7 @@ async fn db_lt_13(services: &Services) -> Result<()> {
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
services.globals.db.bump_database_version(13)?;
|
services.globals.db.bump_database_version(13);
|
||||||
info!("Migration: 12 -> 13 finished");
|
info!("Migration: 12 -> 13 finished");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue