You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow sqlite migrations for non-default databases.
The database will be selected by the name of the migration file. This
makes the name of the migration file significant, whereas previously it
was not. If the name of the file and a known database don't line up,
`spin up` will fail with an error message.
Signed-off-by: Ryan Levick <[email protected]>
Copy file name to clipboardExpand all lines: crates/trigger/src/runtime_config/sqlite.rs
+14-8Lines changed: 14 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -49,24 +49,30 @@ async fn execute_statements(
49
49
if statements.is_empty(){
50
50
returnOk(());
51
51
}
52
-
letSome(default) = databases.get("default")else{
53
-
debug_assert!(
54
-
false,
55
-
"the 'default' sqlite database should always be available but for some reason was not"
56
-
);
57
-
returnOk(());
58
-
};
59
52
60
53
for m in statements {
61
54
ifletSome(file) = m.strip_prefix('@'){
55
+
let database = file.strip_suffix(".sql").unwrap_or(file);
56
+
let database = databases.get(database).with_context(|| {
57
+
format!(
58
+
"based on the sql file '{file}' a registered database named '{database}' was expected but not found. The registered databases are '{:?}'", databases.keys()
59
+
)
60
+
})?;
62
61
let sql = std::fs::read_to_string(file).with_context(|| {
63
62
format!("could not read file '{file}' containing sql statements")
64
63
})?;
65
-
default
64
+
database
66
65
.execute_batch(&sql)
67
66
.await
68
67
.with_context(|| format!("failed to execute sql from file '{file}'"))?;
69
68
}else{
69
+
letSome(default) = databases.get("default")else{
70
+
debug_assert!(
71
+
false,
72
+
"the 'default' sqlite database should always be available but for some reason was not"
0 commit comments