Read data-{platform}.sql in addition to data.sql
Update DataSourceAutoConfiguration to read platform specific `data.sql` files in the same way as `schema.sql` files. Fixes gh-837
This commit is contained in:
parent
bd38893f55
commit
254b175c0a
|
@ -96,9 +96,11 @@ public class DataSourceAutoConfiguration implements EnvironmentAware {
|
||||||
|
|
||||||
String schema = this.datasourceProperties.getProperty("schema");
|
String schema = this.datasourceProperties.getProperty("schema");
|
||||||
if (schema == null) {
|
if (schema == null) {
|
||||||
schema = "classpath*:schema-"
|
String platform = this.datasourceProperties.getProperty("platform", "all");
|
||||||
+ this.datasourceProperties.getProperty("platform", "all")
|
schema = "classpath*:schema-" + platform + ".sql,";
|
||||||
+ ".sql,classpath*:schema.sql,classpath*:data.sql";
|
schema += "classpath*:schema.sql,";
|
||||||
|
schema += "classpath*:data-" + platform + ".sql,";
|
||||||
|
schema += "classpath*:data.sql";
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Resource> resources = new ArrayList<Resource>();
|
List<Resource> resources = new ArrayList<Resource>();
|
||||||
|
|
|
@ -1062,7 +1062,8 @@ not something you want to be on the classpath in production. It is a Hibernate f
|
||||||
=== Initialize a database using Spring JDBC
|
=== Initialize a database using Spring JDBC
|
||||||
Spring JDBC has a `DataSource` initializer feature. Spring Boot enables it by default and
|
Spring JDBC has a `DataSource` initializer feature. Spring Boot enables it by default and
|
||||||
loads SQL from the standard locations `schema.sql` and `data.sql` (in the root of the
|
loads SQL from the standard locations `schema.sql` and `data.sql` (in the root of the
|
||||||
classpath). In addition Spring Boot will load a file `schema-${platform}.sql` where
|
classpath). In addition Spring Boot will load the `schema-${platform}.sql`
|
||||||
|
and `data-${platform}.sql` files (if present), where
|
||||||
`platform` is the value of `spring.datasource.platform`, e.g. you might choose to set
|
`platform` is the value of `spring.datasource.platform`, e.g. you might choose to set
|
||||||
it to the vendor name of the database (`hsqldb`, `h2`, `oracle`, `mysql`,
|
it to the vendor name of the database (`hsqldb`, `h2`, `oracle`, `mysql`,
|
||||||
`postgresql` etc.). Spring Boot enables the failfast feature of the Spring JDBC
|
`postgresql` etc.). Spring Boot enables the failfast feature of the Spring JDBC
|
||||||
|
|
Loading…
Reference in New Issue