sqlx_core/any/
migrate.rs

1use crate::any::driver;
2use crate::any::{Any, AnyConnection};
3use crate::error::Error;
4use crate::migrate::{AppliedMigration, Migrate, MigrateDatabase, MigrateError, Migration};
5use futures_core::future::BoxFuture;
6use std::time::Duration;
7
8impl MigrateDatabase for Any {
9    fn create_database(url: &str) -> BoxFuture<'_, Result<(), Error>> {
10        Box::pin(async {
11            driver::from_url_str(url)?
12                .get_migrate_database()?
13                .create_database(url)
14                .await
15        })
16    }
17
18    fn database_exists(url: &str) -> BoxFuture<'_, Result<bool, Error>> {
19        Box::pin(async {
20            driver::from_url_str(url)?
21                .get_migrate_database()?
22                .database_exists(url)
23                .await
24        })
25    }
26
27    fn drop_database(url: &str) -> BoxFuture<'_, Result<(), Error>> {
28        Box::pin(async {
29            driver::from_url_str(url)?
30                .get_migrate_database()?
31                .drop_database(url)
32                .await
33        })
34    }
35
36    fn force_drop_database(url: &str) -> BoxFuture<'_, Result<(), Error>> {
37        Box::pin(async {
38            driver::from_url_str(url)?
39                .get_migrate_database()?
40                .force_drop_database(url)
41                .await
42        })
43    }
44}
45
46impl Migrate for AnyConnection {
47    fn ensure_migrations_table(&mut self) -> BoxFuture<'_, Result<(), MigrateError>> {
48        Box::pin(async { self.get_migrate()?.ensure_migrations_table().await })
49    }
50
51    fn dirty_version(&mut self) -> BoxFuture<'_, Result<Option<i64>, MigrateError>> {
52        Box::pin(async { self.get_migrate()?.dirty_version().await })
53    }
54
55    fn list_applied_migrations(
56        &mut self,
57    ) -> BoxFuture<'_, Result<Vec<AppliedMigration>, MigrateError>> {
58        Box::pin(async { self.get_migrate()?.list_applied_migrations().await })
59    }
60
61    fn lock(&mut self) -> BoxFuture<'_, Result<(), MigrateError>> {
62        Box::pin(async { self.get_migrate()?.lock().await })
63    }
64
65    fn unlock(&mut self) -> BoxFuture<'_, Result<(), MigrateError>> {
66        Box::pin(async { self.get_migrate()?.unlock().await })
67    }
68
69    fn apply<'e: 'm, 'm>(
70        &'e mut self,
71        migration: &'m Migration,
72    ) -> BoxFuture<'m, Result<Duration, MigrateError>> {
73        Box::pin(async { self.get_migrate()?.apply(migration).await })
74    }
75
76    fn revert<'e: 'm, 'm>(
77        &'e mut self,
78        migration: &'m Migration,
79    ) -> BoxFuture<'m, Result<Duration, MigrateError>> {
80        Box::pin(async { self.get_migrate()?.revert(migration).await })
81    }
82}