revolt_database/models/admin_migrations/ops/
mongodb.rs1use crate::MongoDb;
2
3use super::AbstractMigrations;
4
5mod init;
6mod scripts;
7
8#[async_trait]
9impl AbstractMigrations for MongoDb {
10 #[cfg(test)]
11 async fn drop_database(&self) {
13 self.db().drop().await.ok();
14 }
15
16 async fn migrate_database(&self) -> Result<(), ()> {
18 info!("Migrating the database.");
19
20 let list = self
21 .list_database_names()
22 .await
23 .expect("Failed to fetch database names.");
24
25 if list.iter().any(|x| x == &self.1) {
26 scripts::migrate_database(self).await;
27 } else {
28 init::create_database(self).await;
29 }
30
31 Ok(())
32 }
33}