Skip to content

Commit 85a3fcf

Browse files
committed
Merge branch '2.2.x'
Closes gh-21119
2 parents 961be0f + 5ed27dd commit 85a3fcf

File tree

1 file changed

+21
-5
lines changed
  • spring-boot-project/spring-boot-docs/src/docs/asciidoc

1 file changed

+21
-5
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc

+21-5
Original file line numberDiff line numberDiff line change
@@ -1946,23 +1946,32 @@ For example, you might choose to set it to the vendor name of the database (`hsq
19461946

19471947
[NOTE]
19481948
====
1949-
Spring Boot automatically creates the schema of an embedded `DataSource`.
1949+
When only basic SQL scripts are used, Spring Boot automatically creates the schema of an embedded `DataSource`.
19501950
This behavior can be customized by using the configprop:spring.datasource.initialization-mode[] property.
19511951
For instance, if you want to always initialize the `DataSource` regardless of its type:
19521952
19531953
[indent=0,subs="verbatim,quotes,attributes"]
19541954
----
19551955
spring.datasource.initialization-mode=always
19561956
----
1957+
1958+
In a JPA-based app, you can choose to let Hibernate create the schema or use `schema.sql`, but you cannot do both.
1959+
Make sure to disable `spring.jpa.hibernate.ddl-auto` if you use `schema.sql`.
1960+
1961+
[indent=0,subs="verbatim,quotes,attributes"]
1962+
----
1963+
spring.jpa.hibernate.ddl-auto=none
1964+
----
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.
1968+
It is not possible to use a Database Migration Tool to manage schema creation, and a basic SQL script to initialize it.
19571969
====
19581970

19591971
By default, Spring Boot enables the fail-fast feature of the Spring JDBC initializer.
19601972
This means that, if the scripts cause exceptions, the application fails to start.
19611973
You can tune that behavior by setting `spring.datasource.continue-on-error`.
19621974

1963-
NOTE: In a JPA-based app, you can choose to let Hibernate create the schema or use `schema.sql`, but you cannot do both.
1964-
Make sure to disable `spring.jpa.hibernate.ddl-auto` if you use `schema.sql`.
1965-
19661975

19671976

19681977
[[howto-initialize-a-database-using-r2dbc]]
@@ -2071,6 +2080,13 @@ With that setup, migrations in `dev/db/migration` run only when the `dev` profil
20712080
==== Execute Liquibase Database Migrations on Startup
20722081
To automatically run Liquibase database migrations on startup, add the `org.liquibase:liquibase-core` to your classpath.
20732082

2083+
[NOTE]
2084+
====
2085+
When you add the `org.liquibase:liquibase-core` to your classpath, database migrations run by default for both during application startup and before your tests run.
2086+
This behavior can be customized by using the configprop:spring.liquibase.enabled[] property, setting different values in the `main` and `test` configurations.
2087+
It is not possible to use two different ways to initialize the database (e.g. Liquibase for application startup, JPA for test runs).
2088+
====
2089+
20742090
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`.
20752091
In addition to YAML, Liquibase also supports JSON, XML, and SQL change log formats.
20762092

@@ -2079,7 +2095,7 @@ If you need to use a different `DataSource`, you can create one and mark its `@B
20792095
If you do so and you want two data sources, remember to create another one and mark it as `@Primary`.
20802096
Alternatively, you can use Liquibase's native `DataSource` by setting `spring.liquibase.[url,user,password]` in external properties.
20812097
Setting either `spring.liquibase.url` or `spring.liquibase.user` is sufficient to cause Liquibase to use its own `DataSource`.
2082-
If any of the three properties has not be set, the value of its equivalent `spring.datasource` property will be used.
2098+
If any of the three properties has not been set, the value of its equivalent `spring.datasource` property will be used.
20832099

20842100
See {spring-boot-autoconfigure-module-code}/liquibase/LiquibaseProperties.java[`LiquibaseProperties`] for details about available settings such as contexts, the default schema, and others.
20852101

0 commit comments

Comments
 (0)