From 254b175c0a0f372d2bb7ba947c399a1a13a47307 Mon Sep 17 00:00:00 2001 From: Lukasz Kryger Date: Sat, 10 May 2014 15:26:50 +0100 Subject: [PATCH] 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 --- .../autoconfigure/jdbc/DataSourceAutoConfiguration.java | 8 +++++--- spring-boot-docs/src/main/asciidoc/howto.adoc | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java index ad0d88961a..dc067c899f 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java @@ -96,9 +96,11 @@ public class DataSourceAutoConfiguration implements EnvironmentAware { String schema = this.datasourceProperties.getProperty("schema"); if (schema == null) { - schema = "classpath*:schema-" - + this.datasourceProperties.getProperty("platform", "all") - + ".sql,classpath*:schema.sql,classpath*:data.sql"; + String platform = this.datasourceProperties.getProperty("platform", "all"); + schema = "classpath*:schema-" + platform + ".sql,"; + schema += "classpath*:schema.sql,"; + schema += "classpath*:data-" + platform + ".sql,"; + schema += "classpath*:data.sql"; } List resources = new ArrayList(); diff --git a/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-docs/src/main/asciidoc/howto.adoc index 61a77dde5e..8387adffc4 100644 --- a/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -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 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 -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 it to the vendor name of the database (`hsqldb`, `h2`, `oracle`, `mysql`, `postgresql` etc.). Spring Boot enables the failfast feature of the Spring JDBC