fix: migration script would panic on fresh installations since it couldn't find invites collection
Signed-off-by: İspik <ispik@ispik.dev>
This commit is contained in:
@@ -1478,7 +1478,7 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 {
|
|||||||
if revision <= 50 {
|
if revision <= 50 {
|
||||||
info!("Running migration [revision 50 / 13-04-2026]: Rename invites collection to account_invites");
|
info!("Running migration [revision 50 / 13-04-2026]: Rename invites collection to account_invites");
|
||||||
|
|
||||||
db.db()
|
let result = db.db()
|
||||||
.client()
|
.client()
|
||||||
.database("admin")
|
.database("admin")
|
||||||
.run_command(doc! {
|
.run_command(doc! {
|
||||||
@@ -1486,8 +1486,14 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 {
|
|||||||
"to": "revolt.account_invites",
|
"to": "revolt.account_invites",
|
||||||
"dropTarget": true
|
"dropTarget": true
|
||||||
})
|
})
|
||||||
.await
|
.await;
|
||||||
.unwrap();
|
|
||||||
|
if let Err(e) = result {
|
||||||
|
// NamespaceNotFound (26) = source collection doesn't exist, safe to ignore
|
||||||
|
if !matches!(e.kind.as_ref(), mongodb::error::ErrorKind::Command(ce) if ce.code == 26) {
|
||||||
|
panic!("Failed to rename invites collection: {e}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reminder to update LATEST_REVISION when adding new migrations.
|
// Reminder to update LATEST_REVISION when adding new migrations.
|
||||||
|
|||||||
Reference in New Issue
Block a user