In Spring Modulith, we would like to trigger some database initialization for embedded databases by default. A pull request has submitted a custom SpringBootCondition implementation to detect those cases.

However, an EmbeddedDatabaseCondition already exists in Boot and I would like to avoid the detection algorithms to diverge. I wonder if the class could either be promoted to a public class, or, as all other condition classes seem to be non-public, too, a dedicated @ConditionalOnEmbeddedDatabase could be introduced.

Comment From: wilkinsona

Does this only need to work when Spring Boot's auto-configuration has created the DataSource or should it also support a user-defined DataSource that's providing access to an embedded database? The former might allow EmbeddedDatabaseCondition to be used but the latter would not. The latter might require something similar to the logic in DevToolsDataSourceAutoConfiguration which I'm not sure I'd recommend as it's caused a few bugs over the years.

Comment From: odrotbohm

The fundamental goal is to not run the database initialization when using a "real" (external) database, but still provide the convenience of the schema to be initialized if you run your app on an embedded one, assuming a development environment or test execution. I think it would be fine for use to only opt into the schema creation if it's Boot autoconfigured embedded database. A user-defined, embedded one would then get the automatic schema initialization, but I think the scenario is a bit more of a corner case, that we could expect the user having to explicit activate the schema initialization for that.

Comment From: wilkinsona

We discussed this today and concluded that we do not want to make EmbeddedDatabaseCondition public, either directly or through something like @ConditionalOnEmbeddedDatabase as we don't think it's really suitable for general use. We would like to provide an alternative instead, however.

EmbeddedDataCondition answers a very specific question for the purposes of DataSourceAutoConfiguration. As hinted at above, its answer will only be correct when the auto-configuration has defined the DataSource. If the DataSource has been defined by some other means, it won't consider it and may give an incorrect answer. That could be OK for Spring Modulith's purposes, but we don't think it would be OK for a generally available public API.

As an alternative, we think it could be generally useful to be able to detect whether or not a particular DataSource is embedded. That could be useful both for Spring Modulith and as a more robust way to implement DevToolsDataSourceCondition.

Comment From: odrotbohm

Thanks for considering this. Happy to pick up whatever you decide is the best way forward for Boot.