Skip to content

Commit afb6b10

Browse files
authored
improve docs about migration files (#2566)
1 parent 56ccdd2 commit afb6b10

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

sqlx-core/src/migrate/source.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,24 @@ use std::borrow::Cow;
77
use std::fmt::Debug;
88
use std::path::{Path, PathBuf};
99

10+
/// In the default implementation, a MigrationSource is a directory which
11+
/// contains the migration SQL scripts. All these scripts must be stored in
12+
/// files with names using the format `<VERSION>_<DESCRIPTION>.sql`, where
13+
/// `<VERSION>` is a string that can be parsed into `i64` and its value is
14+
/// greater than zero, and `<DESCRIPTION>` is a string.
15+
///
16+
/// Files that don't match this format are silently ignored.
17+
///
18+
/// You can create a new empty migration script using sqlx-cli:
19+
/// `sqlx migrate add <DESCRIPTION>`.
20+
///
21+
/// Note that migrations for each database are tracked using the
22+
/// `_sqlx_migrations` table (stored in the database). If a migration's hash
23+
/// changes and it has already been run, this will cause an error.
1024
pub trait MigrationSource<'s>: Debug {
1125
fn resolve(self) -> BoxFuture<'s, Result<Vec<Migration>, BoxDynError>>;
1226
}
1327

14-
/// Implementation of the `MigrationSource` for [std::path::Path].
15-
///
16-
/// The path has to point to a directory, which contains the migration SQL scripts. All these
17-
/// scripts must be stored in files with names using the format `<VERSION>_<DESCRIPTION>.sql`,
18-
/// where `<VERSION>` is a string that can be parsed into `i64` and its value is greater than zero,
19-
/// and `<DESCRIPTION>` is a string.
2028
impl<'s> MigrationSource<'s> for &'s Path {
2129
fn resolve(self) -> BoxFuture<'s, Result<Vec<Migration>, BoxDynError>> {
2230
Box::pin(async move {

0 commit comments

Comments
 (0)