Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traverse symlinks when resolving migrations #2445

Merged
merged 2 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sqlx-core/src/migrate/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ impl<'s> MigrationSource<'s> for &'s Path {
let mut migrations = Vec::new();

while let Some(entry) = s.next().await? {
if !entry.metadata.is_file() {
// std::fs::metadata traverses symlinks
if !std::fs::metadata(&entry.path)?.is_file() {
// not a file; ignore
continue;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/migrate/macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ use std::path::Path;

static EMBEDDED_SIMPLE: Migrator = sqlx::migrate!("tests/migrate/migrations_simple");
static EMBEDDED_REVERSIBLE: Migrator = sqlx::migrate!("tests/migrate/migrations_reversible");
static EMBEDDED_SYMLINK: Migrator = sqlx::migrate!("tests/migrate/migrations_symlink");

#[sqlx_macros::test]
async fn same_output() -> anyhow::Result<()> {
let runtime_simple = Migrator::new(Path::new("tests/migrate/migrations_simple")).await?;
let runtime_reversible =
Migrator::new(Path::new("tests/migrate/migrations_reversible")).await?;
let runtime_symlink = Migrator::new(Path::new("tests/migrate/migrations_symlink")).await?;

assert_same(&EMBEDDED_SIMPLE, &runtime_simple);
assert_same(&EMBEDDED_REVERSIBLE, &runtime_reversible);
assert_same(&EMBEDDED_SYMLINK, &runtime_symlink);

Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions tests/migrate/migrations_symlink