Add onboarding and FromRequest for User.

This commit is contained in:
Paul Makles
2020-12-28 21:47:32 +00:00
parent 16c5a28637
commit 798047625a
13 changed files with 236 additions and 88 deletions

View File

@@ -1,4 +1,4 @@
use super::super::get_collection;
use super::super::{get_db, get_collection};
use log::info;
use mongodb::options::FindOptions;
@@ -12,7 +12,7 @@ struct MigrationInfo {
revision: i32,
}
pub const LATEST_REVISION: i32 = 2;
pub const LATEST_REVISION: i32 = 3;
pub async fn migrate_database() {
let migrations = get_collection("migrations");
@@ -121,6 +121,32 @@ pub async fn run_migrations(revision: i32) -> i32 {
}
}
if revision <= 2 {
info!("Running migration [revision 2]: Add username index to users.");
get_db().run_command(
doc! {
"createIndexes": "users",
"indexes": [
{
"key": {
"username": 1
},
"name": "username",
"unique": true,
"collation": {
"locale": "en",
"strength": 2
}
}
]
},
None
)
.await
.expect("Failed to create username index.");
}
// Reminder to update LATEST_REVISION when adding new migrations.
LATEST_REVISION
}