chore: Add index and migration

This commit is contained in:
Zomatree
2024-07-21 22:12:55 +01:00
parent 389ecc0e5c
commit d2f4823ceb
2 changed files with 32 additions and 2 deletions

View File

@@ -146,7 +146,14 @@ pub async fn create_database(db: &MongoDb) {
"author": 1_i32
},
"name": "author"
}
},
{
"key": {
"channel": 1_i32,
"pinned": 1_i32
},
"name": "channel_pinned_compound"
},
]
},
None,

View File

@@ -20,7 +20,7 @@ struct MigrationInfo {
revision: i32,
}
pub const LATEST_REVISION: i32 = 27;
pub const LATEST_REVISION: i32 = 28;
pub async fn migrate_database(db: &MongoDb) {
let migrations = db.col::<Document>("migrations");
@@ -1071,6 +1071,29 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 {
}
}
if revision <= 27 {
info!("Running migration [revision 27 / 21-07-2024]: create message pinned index.");
db.db()
.run_command(
doc! {
"createIndexes": "messages",
"indexes": [
{
"key": {
"channel": 1_i32,
"pinned": 1_i32
},
"name": "channel_pinned_compound"
}
]
},
None,
)
.await
.expect("Failed to create message index.");
}
// Need to migrate fields on attachments, change `user_id`, `object_id`, etc to `parent`.
// Reminder to update LATEST_REVISION when adding new migrations.