From d936d473562d65a79b3d997bfe2c5a45ffc9613d Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Wed, 3 Jul 2024 15:01:49 +0200 Subject: [PATCH] Don't use migration file name but a ':database' suffix Signed-off-by: Ryan Levick --- crates/trigger/src/runtime_config/sqlite.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/trigger/src/runtime_config/sqlite.rs b/crates/trigger/src/runtime_config/sqlite.rs index 8c48a296f..8d4e2da3a 100644 --- a/crates/trigger/src/runtime_config/sqlite.rs +++ b/crates/trigger/src/runtime_config/sqlite.rs @@ -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(|| {