Logging + database migrations system.

This commit is contained in:
Paul Makles
2020-08-11 21:08:01 +02:00
parent 750f8c6738
commit a8eb403280
9 changed files with 157 additions and 12 deletions

View File

@@ -0,0 +1,39 @@
use super::super::get_db;
use super::scripts::LATEST_REVISION;
use mongodb::options::CreateCollectionOptions;
use mongodb::bson::doc;
use log::info;
pub fn create_database() {
info!("Creating database.");
let db = get_db();
db.create_collection("users", None).expect("Failed to create users collection.");
db.create_collection("channels", None).expect("Failed to create channels collection.");
db.create_collection("guilds", None).expect("Failed to create guilds collection.");
db.create_collection("members", None).expect("Failed to create members collection.");
db.create_collection("messages", None).expect("Failed to create messages collection.");
db.create_collection("migrations", None).expect("Failed to create migrations collection.");
db.create_collection(
"pubsub",
CreateCollectionOptions::builder()
.capped(true)
.size(1_000_000)
.build()
)
.expect("Failed to create pubsub collection.");
db.collection("migrations")
.insert_one(
doc! {
"_id": 0,
"revision": LATEST_REVISION
},
None
)
.expect("Failed to save migration info.");
info!("Created database.");
}