Skip to content

Commit

Permalink
🐛 fix apply migrations on embedded mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Odonno committed Apr 13, 2024
1 parent c77f7aa commit 35f589d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fn get_embedded_file_full_name(f: &include_dir::File) -> Option<String> {

fn get_embedded_file_is_file(full_name: &Option<String>) -> bool {
match full_name {
Some(full_name) => full_name.ends_with(".surql"),
Some(full_name) => full_name.ends_with(".surql") || full_name.ends_with(".json"),
None => false,
}
}
Expand Down
23 changes: 23 additions & 0 deletions tests/library/load_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,26 @@ async fn apply_migrations_from_embedded_files() -> Result<()> {

Ok(())
}

#[tokio::test]
async fn apply_migrations_multiple_times_from_embedded_files() -> Result<()> {
const EMBEDDED_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/embedded-files");

let db_name = generate_random_db_name()?;

let configuration = SurrealdbConfiguration {
db: Some(db_name),
..Default::default()
};

let db = create_surrealdb_client(&configuration).await?;

let runner = MigrationRunner::new(&db);
let runner = runner.load_files(&EMBEDDED_DIR);

runner.up().await?;
runner.up().await?;
runner.up().await?;

Ok(())
}

0 comments on commit 35f589d

Please sign in to comment.