forked from jmug/stoatchat
chore: Add index and migration
This commit is contained in:
@@ -146,7 +146,14 @@ pub async fn create_database(db: &MongoDb) {
|
|||||||
"author": 1_i32
|
"author": 1_i32
|
||||||
},
|
},
|
||||||
"name": "author"
|
"name": "author"
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"channel": 1_i32,
|
||||||
|
"pinned": 1_i32
|
||||||
|
},
|
||||||
|
"name": "channel_pinned_compound"
|
||||||
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ struct MigrationInfo {
|
|||||||
revision: i32,
|
revision: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const LATEST_REVISION: i32 = 27;
|
pub const LATEST_REVISION: i32 = 28;
|
||||||
|
|
||||||
pub async fn migrate_database(db: &MongoDb) {
|
pub async fn migrate_database(db: &MongoDb) {
|
||||||
let migrations = db.col::<Document>("migrations");
|
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`.
|
// Need to migrate fields on attachments, change `user_id`, `object_id`, etc to `parent`.
|
||||||
|
|
||||||
// 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