Start work on notifications from client, cargo fmt

This commit is contained in:
Paul Makles
2020-12-30 11:36:32 +00:00
parent af56f5e2d8
commit f39bc07bb9
34 changed files with 341 additions and 264 deletions

View File

@@ -10,28 +10,28 @@ pub async fn create_database() {
let db = get_db();
db.create_collection("users", None)
.await
.expect("Failed to create users collection.");
.await
.expect("Failed to create users collection.");
db.create_collection("channels", None)
.await
.expect("Failed to create channels collection.");
.await
.expect("Failed to create channels collection.");
db.create_collection("guilds", None)
.await
.expect("Failed to create guilds collection.");
.await
.expect("Failed to create guilds collection.");
db.create_collection("members", None)
.await
.expect("Failed to create members collection.");
.await
.expect("Failed to create members collection.");
db.create_collection("messages", None)
.await
.expect("Failed to create messages collection.");
.await
.expect("Failed to create messages collection.");
db.create_collection("migrations", None)
.await
.expect("Failed to create migrations collection.");
.await
.expect("Failed to create migrations collection.");
db.create_collection(
"pubsub",
@@ -60,21 +60,21 @@ pub async fn create_database() {
}
]
},
None
None,
)
.await
.expect("Failed to create username index.");
db.collection("migrations")
.insert_one(
doc! {
"_id": 0,
"revision": LATEST_REVISION
},
None,
)
.await
.expect("Failed to save migration info.");
.insert_one(
doc! {
"_id": 0,
"revision": LATEST_REVISION
},
None,
)
.await
.expect("Failed to save migration info.");
info!("Created database.");
}

View File

@@ -1,10 +1,10 @@
use super::super::{get_db, get_collection};
use super::super::{get_collection, get_db};
use crate::rocket::futures::StreamExt;
use log::info;
use mongodb::bson::{doc, from_bson, Bson};
use mongodb::options::FindOptions;
use serde::{Deserialize, Serialize};
use crate::rocket::futures::StreamExt;
use mongodb::bson::{doc, from_bson, Bson};
#[derive(Serialize, Deserialize)]
struct MigrationInfo {
@@ -86,7 +86,7 @@ pub async fn run_migrations(revision: i32) -> i32 {
.get_str("_id")
.expect("Failed to get channel id.")
.to_string();
let gid = channel
.get_str("guild")
.expect("Failed to get guild id.")
@@ -124,27 +124,28 @@ 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
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.");
]
},
None,
)
.await
.expect("Failed to create username index.");
}
// Reminder to update LATEST_REVISION when adding new migrations.