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
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc
+17-5Lines changed: 17 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -1949,23 +1949,28 @@ For example, you might choose to set it to the vendor name of the database (`hsq
1949
1949
1950
1950
[NOTE]
1951
1951
====
1952
-
Spring Boot automatically creates the schema of an embedded `DataSource`.
1952
+
When only basic SQL scripts are used, Spring Boot automatically creates the schema of an embedded `DataSource`.
1953
1953
This behavior can be customized by using the configprop:spring.datasource.initialization-mode[] property.
1954
1954
For instance, if you want to always initialize the `DataSource` regardless of its type:
1955
1955
1956
1956
[indent=0,subs="verbatim,quotes,attributes"]
1957
1957
----
1958
1958
spring.datasource.initialization-mode=always
1959
1959
----
1960
+
In a JPA-based app, you can choose to let Hibernate create the schema or use `schema.sql`, but you cannot do both.
1961
+
Make sure to disable `spring.jpa.hibernate.ddl-auto` if you use `schema.sql`.
1962
+
[indent=0,subs="verbatim,quotes,attributes"]
1963
+
----
1964
+
spring.jpa.hibernate.ddl-auto=none
1965
+
----
1966
+
If you are using a <<spring-boot-features.adoc#howto-use-a-higher-level-database-migration-tool,Higher-level Database Migration Tool>>, like Flyway or Liquibase, you cannot use basic SQL scripts to create and initialize the schema.
1967
+
In this situation, if `schema.sql` and `data.sql` are present, they will be ignored. It is not possible to use a Database Migration Tool to manage schema creation, and a basic SQL script to initialize it.
1960
1968
====
1961
1969
1962
1970
By default, Spring Boot enables the fail-fast feature of the Spring JDBC initializer.
1963
1971
This means that, if the scripts cause exceptions, the application fails to start.
1964
1972
You can tune that behavior by setting `spring.datasource.continue-on-error`.
1965
1973
1966
-
NOTE: In a JPA-based app, you can choose to let Hibernate create the schema or use `schema.sql`, but you cannot do both.
1967
-
Make sure to disable `spring.jpa.hibernate.ddl-auto` if you use `schema.sql`.
1968
-
1969
1974
1970
1975
1971
1976
[[howto-initialize-a-spring-batch-database]]
@@ -2056,6 +2061,13 @@ With that setup, migrations in `dev/db/migration` run only when the `dev` profil
2056
2061
==== Execute Liquibase Database Migrations on Startup
2057
2062
To automatically run Liquibase database migrations on startup, add the `org.liquibase:liquibase-core` to your classpath.
2058
2063
2064
+
[NOTE]
2065
+
====
2066
+
When you add the `org.liquibase:liquibase-core` to your classpath, by default database migrations will run for both during application startup and before your tests run.
2067
+
This behavior can be customized by using the configprop:spring.liquibase.enabled[] property, setting different values in the `main` and `test` folders.
2068
+
It is not possible to use two different ways to initialize the database (e.g. Liquibase for application startup, JPA for test runs).
2069
+
====
2070
+
2059
2071
By default, the master change log is read from `db/changelog/db.changelog-master.yaml`, but you can change the location by setting `spring.liquibase.change-log`.
2060
2072
In addition to YAML, Liquibase also supports JSON, XML, and SQL change log formats.
2061
2073
@@ -2064,7 +2076,7 @@ If you need to use a different `DataSource`, you can create one and mark its `@B
2064
2076
If you do so and you want two data sources, remember to create another one and mark it as `@Primary`.
2065
2077
Alternatively, you can use Liquibase's native `DataSource` by setting `spring.liquibase.[url,user,password]` in external properties.
2066
2078
Setting either `spring.liquibase.url` or `spring.liquibase.user` is sufficient to cause Liquibase to use its own `DataSource`.
2067
-
If any of the three properties has not be set, the value of its equivalent `spring.datasource` property will be used.
2079
+
If any of the three properties has not been set, the value of its equivalent `spring.datasource` property will be used.
2068
2080
2069
2081
See {spring-boot-autoconfigure-module-code}/liquibase/LiquibaseProperties.java[`LiquibaseProperties`] for details about available settings such as contexts, the default schema, and others.
0 commit comments