Skip to content

Commit 24be262

Browse files
committed
fix: restore Migrator to the public API
1 parent bbfd0d7 commit 24be262

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

sqlx-core/src/migrate/migrator.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@ use std::collections::{HashMap, HashSet};
55
use std::ops::Deref;
66
use std::slice;
77

8+
/// A resolved set of migrations, ready to be run.
9+
///
10+
/// Can be constructed statically using `migrate!()` or at runtime using [`Migrator::new()`].
811
#[derive(Debug)]
9-
#[doc(hidden)]
12+
// Forbids `migrate!()` from constructing this:
13+
// #[non_exhaustive]
1014
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)]
1119
pub migrations: Cow<'static, [Migration]>,
20+
#[doc(hidden)]
1221
pub ignore_missing: bool,
22+
#[doc(hidden)]
1323
pub locking: bool,
1424
}
1525

@@ -33,6 +43,13 @@ fn validate_applied_migrations(
3343
}
3444

3545
impl Migrator {
46+
#[doc(hidden)]
47+
pub const DEFAULT: Migrator = Migrator {
48+
migrations: Cow::Borrowed(&[]),
49+
ignore_missing: false,
50+
locking: true,
51+
};
52+
3653
/// Creates a new instance with the given source.
3754
///
3855
/// # Examples
@@ -57,8 +74,7 @@ impl Migrator {
5774
{
5875
Ok(Self {
5976
migrations: Cow::Owned(source.resolve().await.map_err(MigrateError::Source)?),
60-
ignore_missing: false,
61-
locking: true,
77+
..Self::DEFAULT
6278
})
6379
}
6480

@@ -68,7 +84,7 @@ impl Migrator {
6884
self
6985
}
7086

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`.
7288
///
7389
/// ### Warning
7490
/// Disabling locking can lead to errors or data loss if multiple clients attempt to apply migrations simultaneously

sqlx-macros-core/src/migrate.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,9 @@ pub(crate) fn expand_migrator(path: &Path) -> crate::Result<TokenStream> {
146146
Ok(quote! {
147147
::sqlx::migrate::Migrator {
148148
migrations: ::std::borrow::Cow::Borrowed(&[
149-
#(#migrations),*
149+
#(#migrations),*
150150
]),
151-
ignore_missing: false,
152-
locking: true,
151+
..::sqlx::migrate::Migrator::DEFAULT
153152
}
154153
})
155154
}

0 commit comments

Comments
 (0)