Reconcile historical Modrinth migration checksums
This commit is contained in:
@@ -8,4 +8,4 @@ All notable Modrinth Plus changes are documented here.
|
|||||||
- Added Gitea Actions verification for the Modrinth Plus fork.
|
- Added Gitea Actions verification for the Modrinth Plus fork.
|
||||||
- Added Windows installer publishing to the Gitea generic package registry.
|
- Added Windows installer publishing to the Gitea generic package registry.
|
||||||
- Added Codex repository context and release/security documentation.
|
- Added Codex repository context and release/security documentation.
|
||||||
- Fixed startup compatibility with existing official Modrinth App databases that recorded a different checksum for the historical initial SQLite migration.
|
- Fixed startup compatibility with existing official Modrinth App databases that recorded different checksums for historical SQLite migrations.
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use std::str::FromStr;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
static MIGRATOR: sqlx::migrate::Migrator = sqlx::migrate!();
|
static MIGRATOR: sqlx::migrate::Migrator = sqlx::migrate!();
|
||||||
const HISTORICAL_INIT_MIGRATION_VERSION: i64 = 20240711194701;
|
const FIRST_MODRINTH_PLUS_MIGRATION_VERSION: i64 = 20260503003000;
|
||||||
|
|
||||||
pub(crate) async fn connect(
|
pub(crate) async fn connect(
|
||||||
app_identifier: &str,
|
app_identifier: &str,
|
||||||
@@ -49,13 +49,6 @@ pub(crate) async fn connect(
|
|||||||
async fn reconcile_historical_migration_checksums(
|
async fn reconcile_historical_migration_checksums(
|
||||||
pool: &Pool<Sqlite>,
|
pool: &Pool<Sqlite>,
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
let Some(init_migration) = MIGRATOR.iter().find(|migration| {
|
|
||||||
migration.version == HISTORICAL_INIT_MIGRATION_VERSION
|
|
||||||
})
|
|
||||||
else {
|
|
||||||
return Ok(());
|
|
||||||
};
|
|
||||||
|
|
||||||
let has_migration_table: i64 = sqlx::query_scalar(
|
let has_migration_table: i64 = sqlx::query_scalar(
|
||||||
"SELECT COUNT(*) FROM sqlite_master WHERE type = 'table' AND name = '_sqlx_migrations'",
|
"SELECT COUNT(*) FROM sqlite_master WHERE type = 'table' AND name = '_sqlx_migrations'",
|
||||||
)
|
)
|
||||||
@@ -66,29 +59,33 @@ async fn reconcile_historical_migration_checksums(
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let stored_checksum: Option<Vec<u8>> = sqlx::query_scalar(
|
for migration in MIGRATOR.iter().filter(|migration| {
|
||||||
"SELECT checksum FROM _sqlx_migrations WHERE version = ? AND success = TRUE",
|
migration.version < FIRST_MODRINTH_PLUS_MIGRATION_VERSION
|
||||||
)
|
}) {
|
||||||
.bind(HISTORICAL_INIT_MIGRATION_VERSION)
|
let stored_checksum: Option<Vec<u8>> = sqlx::query_scalar(
|
||||||
.fetch_optional(pool)
|
"SELECT checksum FROM _sqlx_migrations WHERE version = ? AND success = TRUE",
|
||||||
.await?;
|
)
|
||||||
|
.bind(migration.version)
|
||||||
|
.fetch_optional(pool)
|
||||||
|
.await?;
|
||||||
|
|
||||||
if let Some(stored_checksum) = stored_checksum {
|
if let Some(stored_checksum) = stored_checksum {
|
||||||
let bundled_checksum: &[u8] = init_migration.checksum.as_ref();
|
let bundled_checksum: &[u8] = migration.checksum.as_ref();
|
||||||
|
|
||||||
if stored_checksum.as_slice() != bundled_checksum {
|
if stored_checksum.as_slice() != bundled_checksum {
|
||||||
tracing::warn!(
|
tracing::warn!(
|
||||||
"Reconciling checksum for historical Modrinth init migration {}",
|
"Reconciling checksum for historical Modrinth migration {}",
|
||||||
HISTORICAL_INIT_MIGRATION_VERSION
|
migration.version
|
||||||
);
|
);
|
||||||
|
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
"UPDATE _sqlx_migrations SET checksum = ? WHERE version = ? AND success = TRUE",
|
"UPDATE _sqlx_migrations SET checksum = ? WHERE version = ? AND success = TRUE",
|
||||||
)
|
)
|
||||||
.bind(bundled_checksum)
|
.bind(bundled_checksum)
|
||||||
.bind(HISTORICAL_INIT_MIGRATION_VERSION)
|
.bind(migration.version)
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user