Skip to content

Commit

Permalink
Don't use migration file name but a ':database' suffix
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Levick <[email protected]>
  • Loading branch information
rylev committed Jul 22, 2024
1 parent f83eaa5 commit d936d47
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions crates/trigger/src/runtime_config/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,16 @@ async fn execute_statements(
}

for m in statements {
if let Some(file) = m.strip_prefix('@') {
let database = file.strip_suffix(".sql").unwrap_or(file);
if let Some(config) = m.strip_prefix('@') {
let config = config.trim();
let (file, database) = match config.split_once(':') {
Some((file, database)) if database.trim().is_empty() => (file.trim(), "default"),
Some((file, database)) => (file.trim(), database.trim()),
None => (config, "default"),
};
let database = databases.get(database).with_context(|| {
format!(
"based on the sql file '{file}' a registered database named '{database}' was expected but not found. The registered databases are '{:?}'", databases.keys()
"based on the '@{config}' a registered database named '{database}' was expected but not found. The registered databases are '{:?}'", databases.keys()
)
})?;
let sql = std::fs::read_to_string(file).with_context(|| {
Expand Down

0 comments on commit d936d47

Please sign in to comment.