create db migration function
will contain indexes
This commit is contained in:
parent
08167143aa
commit
41ac1d7cea
@ -3,12 +3,13 @@ use chrono::{DateTime, Utc};
|
|||||||
use enum_stringify::EnumStringify;
|
use enum_stringify::EnumStringify;
|
||||||
use futures::stream::{StreamExt, TryStreamExt};
|
use futures::stream::{StreamExt, TryStreamExt};
|
||||||
|
|
||||||
use mongodb::Database;
|
use mongodb::options::IndexOptions;
|
||||||
use mongodb::{
|
use mongodb::{
|
||||||
bson::doc,
|
bson::doc,
|
||||||
options::{ClientOptions, ResolverConfig},
|
options::{ClientOptions, ResolverConfig},
|
||||||
Client,
|
Client,
|
||||||
};
|
};
|
||||||
|
use mongodb::{Database, IndexModel};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(EnumStringify)]
|
#[derive(EnumStringify)]
|
||||||
@ -80,6 +81,19 @@ impl DB {
|
|||||||
|
|
||||||
DB { client }
|
DB { client }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn migrate(&mut self) -> Result<(), mongodb::error::Error> {
|
||||||
|
let events = self.get_database().await.collection::<Event>("events");
|
||||||
|
events
|
||||||
|
.create_index(
|
||||||
|
IndexModel::builder()
|
||||||
|
.keys(doc! {"time": 1})
|
||||||
|
.options(IndexOptions::builder().unique(true).build())
|
||||||
|
.build(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user