@@ -5,11 +5,21 @@ use std::collections::{HashMap, HashSet};
5
5
use std:: ops:: Deref ;
6
6
use std:: slice;
7
7
8
+ /// A resolved set of migrations, ready to be run.
9
+ ///
10
+ /// Can be constructed statically using `migrate!()` or at runtime using [`Migrator::new()`].
8
11
#[ derive( Debug ) ]
9
- #[ doc( hidden) ]
12
+ // Forbids `migrate!()` from constructing this:
13
+ // #[non_exhaustive]
10
14
pub struct Migrator {
15
+ // NOTE: these fields are semver-exempt and may be changed or removed in any future version.
16
+ // These have to be public for `migrate!()` to be able to initialize them in an implicitly
17
+ // const-promotable context. A `const fn` constructor isn't implicitly const-promotable.
18
+ #[ doc( hidden) ]
11
19
pub migrations : Cow < ' static , [ Migration ] > ,
20
+ #[ doc( hidden) ]
12
21
pub ignore_missing : bool ,
22
+ #[ doc( hidden) ]
13
23
pub locking : bool ,
14
24
}
15
25
@@ -33,6 +43,13 @@ fn validate_applied_migrations(
33
43
}
34
44
35
45
impl Migrator {
46
+ #[ doc( hidden) ]
47
+ pub const DEFAULT : Migrator = Migrator {
48
+ migrations : Cow :: Borrowed ( & [ ] ) ,
49
+ ignore_missing : false ,
50
+ locking : true ,
51
+ } ;
52
+
36
53
/// Creates a new instance with the given source.
37
54
///
38
55
/// # Examples
@@ -57,8 +74,7 @@ impl Migrator {
57
74
{
58
75
Ok ( Self {
59
76
migrations : Cow :: Owned ( source. resolve ( ) . await . map_err ( MigrateError :: Source ) ?) ,
60
- ignore_missing : false ,
61
- locking : true ,
77
+ ..Self :: DEFAULT
62
78
} )
63
79
}
64
80
@@ -68,7 +84,7 @@ impl Migrator {
68
84
self
69
85
}
70
86
71
- /// Specify whether or not to lock database during migration. Defaults to `true`.
87
+ /// Specify whether or not to lock the database during migration. Defaults to `true`.
72
88
///
73
89
/// ### Warning
74
90
/// Disabling locking can lead to errors or data loss if multiple clients attempt to apply migrations simultaneously
0 commit comments