Skip to content

Commit 101e4b2

Browse files
committed
fix: create the schema when the database does not exist yet
1 parent 1df5050 commit 101e4b2

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

‎cmd/mxcli/docker/runtime_controller.go‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,29 @@ func (c *RuntimeController) ApplyBuild(build *BuildResult, restart func() error)
203203
return action, nil
204204
}
205205

206-
// needsDBUpdate reports whether a start response indicates the database schema
207-
// must be updated before the runtime can serve (result 3 / "database has to be
208-
// updated" / a synchronizationreason in the feedback).
206+
// needsDBUpdate reports whether a start response indicates the database must be
207+
// created or updated before the runtime can serve.
208+
//
209+
// Two results mean that, and both need the same response (execute_ddl_commands
210+
// then start again):
211+
//
212+
// - result 3, "the database has to be updated" — the schema is out of date.
213+
// - result 2, "the database to be used does not exist" — there is no schema at
214+
// all. This is the normal first boot of the built-in HSQLDB database, whose
215+
// JDBC URL carries ifexists=true and therefore never creates the file.
216+
//
217+
// The synchronizationreason feedback is a third signal the runtime sometimes
218+
// sends instead of the message.
209219
func needsDBUpdate(resp *M2EEResponse) bool {
210220
if resp == nil {
211221
return false
212222
}
213-
if resp.Result == 3 {
223+
if resp.Result == 2 || resp.Result == 3 {
214224
return true
215225
}
216-
if strings.Contains(strings.ToLower(resp.Message), "database has to be updated") {
226+
lower := strings.ToLower(resp.Message)
227+
if strings.Contains(lower, "database has to be updated") ||
228+
strings.Contains(lower, "database to be used does not exist") {
217229
return true
218230
}
219231
if fb := resp.Feedback(); fb != nil {

‎cmd/mxcli/docker/runtime_controller_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ func TestNeedsDBUpdate(t *testing.T) {
344344
{"clean", &M2EEResponse{}, false},
345345
{"result3", &M2EEResponse{Result: 3}, true},
346346
{"message", &M2EEResponse{Message: "The database has to be updated first"}, true},
347+
{"result2", &M2EEResponse{Result: 2}, true},
348+
{"no-existing-db-message", &M2EEResponse{Message: "The database to be used does not exist."}, true},
347349
{"feedback", &M2EEResponse{RawFeedback: json.RawMessage(`{"synchronizationreason":"x"}`)}, true},
348350
{"other-error", &M2EEResponse{Result: 1, Message: "unrelated"}, false},
349351
}

0 commit comments

Comments
 (0)