-
Notifications
You must be signed in to change notification settings - Fork 213
/
diagnose_migration_history.rs
74 lines (63 loc) 路 2.33 KB
/
diagnose_migration_history.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use migration_core::{
commands::DiagnoseMigrationHistoryOutput,
commands::{diagnose_migration_history, DiagnoseMigrationHistoryInput},
migration_connector::MigrationConnector,
CoreError, CoreResult,
};
use tempfile::TempDir;
#[must_use = "This struct does nothing on its own. See DiagnoseMigrationHistory::send()"]
pub struct DiagnoseMigrationHistory<'a> {
api: &'a mut dyn MigrationConnector,
migrations_directory: &'a TempDir,
opt_in_to_shadow_database: bool,
}
impl<'a> DiagnoseMigrationHistory<'a> {
pub fn new(api: &'a mut dyn MigrationConnector, migrations_directory: &'a TempDir) -> Self {
DiagnoseMigrationHistory {
api,
migrations_directory,
opt_in_to_shadow_database: false,
}
}
pub fn opt_in_to_shadow_database(mut self, opt_in_to_shadow_database: bool) -> Self {
self.opt_in_to_shadow_database = opt_in_to_shadow_database;
self
}
pub async fn send(self) -> CoreResult<DiagnoseMigrationHistoryAssertions<'a>> {
let output = diagnose_migration_history(
DiagnoseMigrationHistoryInput {
migrations_directory_path: self.migrations_directory.path().to_str().unwrap().to_owned(),
opt_in_to_shadow_database: self.opt_in_to_shadow_database,
},
None,
self.api,
)
.await?;
Ok(DiagnoseMigrationHistoryAssertions {
output,
_migrations_directory: self.migrations_directory,
})
}
#[track_caller]
pub fn send_sync(self) -> DiagnoseMigrationHistoryAssertions<'a> {
test_setup::runtime::run_with_thread_local_runtime(self.send()).unwrap()
}
#[track_caller]
pub fn send_unwrap_err(self) -> CoreError {
test_setup::runtime::run_with_thread_local_runtime(self.send()).unwrap_err()
}
}
pub struct DiagnoseMigrationHistoryAssertions<'a> {
output: DiagnoseMigrationHistoryOutput,
_migrations_directory: &'a TempDir,
}
impl std::fmt::Debug for DiagnoseMigrationHistoryAssertions<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "DiagnoseMigrationHistoryAssertions {{ .. }}")
}
}
impl<'a> DiagnoseMigrationHistoryAssertions<'a> {
pub fn into_output(self) -> DiagnoseMigrationHistoryOutput {
self.output
}
}