fix: pre-migration for skins drag and drop change (#6402)

This commit is contained in:
Calum H.
2026-06-19 15:16:51 +01:00
committed by GitHub
parent d33f00d2b1
commit d2b85c9f8e
2 changed files with 39 additions and 4 deletions
@@ -0,0 +1,20 @@
{
"db_name": "SQLite",
"query": "SELECT COUNT(*) AS \"count!: i64\" FROM sqlite_master WHERE type = 'table' AND name IN ('custom_minecraft_skins', 'minecraft_users')",
"describe": {
"columns": [
{
"name": "count!: i64",
"ordinal": 0,
"type_info": "Integer"
}
],
"parameters": {
"Right": 0
},
"nullable": [
false
]
},
"hash": "01d62695f1845e5258d7e39fd80a61cff39b759f832b89e6491d29dc51c18714"
}
+19 -4
View File
@@ -31,6 +31,12 @@ pub(crate) async fn connect(
.connect_with(conn_options)
.await?;
if let Err(err) = stale_data_cleanup(&pool).await {
tracing::warn!(
"Failed to clean up stale data from state database before migrations: {err}"
);
}
sqlx::migrate!().run(&pool).await?;
if let Err(err) = stale_data_cleanup(&pool).await {
@@ -48,11 +54,20 @@ pub(crate) async fn connect(
async fn stale_data_cleanup(pool: &Pool<Sqlite>) -> crate::Result<()> {
let mut tx = pool.begin().await?;
sqlx::query!(
"DELETE FROM custom_minecraft_skins WHERE minecraft_user_uuid NOT IN (SELECT uuid FROM minecraft_users)"
let has_skin_tables = sqlx::query!(
"SELECT COUNT(*) AS \"count!: i64\" FROM sqlite_master WHERE type = 'table' AND name IN ('custom_minecraft_skins', 'minecraft_users')",
)
.execute(&mut *tx)
.await?;
.fetch_one(&mut *tx)
.await?
.count == 2;
if has_skin_tables {
sqlx::query!(
"DELETE FROM custom_minecraft_skins WHERE minecraft_user_uuid NOT IN (SELECT uuid FROM minecraft_users)"
)
.execute(&mut *tx)
.await?;
}
tx.commit().await?;