From 4e1f1c116cd2a7f648889ce8f0c8a951024fb90e Mon Sep 17 00:00:00 2001 From: Zomatree Date: Mon, 30 Mar 2026 15:09:46 +0100 Subject: [PATCH] fix: add migration to update existing files to be animated Signed-off-by: Zomatree --- .../admin_migrations/ops/mongodb/scripts.rs | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/crates/core/database/src/models/admin_migrations/ops/mongodb/scripts.rs b/crates/core/database/src/models/admin_migrations/ops/mongodb/scripts.rs index 174a81a6..a1ba7386 100644 --- a/crates/core/database/src/models/admin_migrations/ops/mongodb/scripts.rs +++ b/crates/core/database/src/models/admin_migrations/ops/mongodb/scripts.rs @@ -25,7 +25,7 @@ struct MigrationInfo { revision: i32, } -pub const LATEST_REVISION: i32 = 50; // MUST BE +1 to last migration +pub const LATEST_REVISION: i32 = 51; // MUST BE +1 to last migration pub async fn migrate_database(db: &MongoDb) { let migrations = db.col::("migrations"); @@ -1085,7 +1085,7 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 { enum Channel { Group { owner: String }, TextChannel { server: String }, - VoiceChannel { server: String } + VoiceChannel { server: String }, } let webhooks = db @@ -1099,7 +1099,12 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 { .await; for webhook in webhooks { - match db.col::("channels").find_one(doc! { "_id": &webhook.channel_id }).await.unwrap() { + match db + .col::("channels") + .find_one(doc! { "_id": &webhook.channel_id }) + .await + .unwrap() + { Some(channel) => { let creator_id = match channel { Channel::Group { owner, .. } => owner, @@ -1240,7 +1245,7 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 { "channel_type": "TextChannel", "voice": {} } - } + }, ) .await .expect("Failed to update voice channels"); @@ -1292,10 +1297,7 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 { let mut doc = doc! {}; for id in server.roles.keys() { - doc.insert( - format!("roles.{id}._id"), - id, - ); + doc.insert(format!("roles.{id}._id"), id); } db.db() @@ -1306,6 +1308,24 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 { } }; + if revision <= 50 { + info!("Running migration [revision 50 / 30-03-2026]: Add animated to existing gifs"); + + db.db() + .collection::("attachment_hashes") + .update_many( + doc! { + "content_type": "image/gif", + "metadata.type": "Image", + }, + doc! { + "metadata.animated": true + }, + ) + .await + .expect("Failed to update attachment_hashes"); + }; + // Reminder to update LATEST_REVISION when adding new migrations. LATEST_REVISION.max(revision) }