Skip to content

Commit 7e33320

Browse files
committed
Revise "Use Liquibase for test-only migrations" section in reference manual
Closes gh-39539 Signed-off-by: Vedran Pavic <vedran@vedranpavic.com>
1 parent 7a235ca commit 7e33320

File tree

1 file changed

+2
-35
lines changed

1 file changed

+2
-35
lines changed

spring-boot-project/spring-boot-docs/src/docs/antora/modules/how-to/pages/data-initialization.adoc

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -207,41 +207,8 @@ This file will not be packaged in your uber jar or your container.
207207
[[howto.data-initialization.migration-tool.liquibase-tests]]
208208
=== Use Liquibase for Test-only Migrations
209209

210-
If you want to create Liquibase migrations which populate your test database, you have to create a test changelog which also includes the production changelog.
211-
212-
First, you need to configure Liquibase to use a different changelog when running the tests.
213-
One way to do this is to create a Spring Boot `test` profile and put the Liquibase properties in there.
214-
For that, create a file named `src/test/resources/application-test.properties` and put the following property in there:
215-
216-
[configprops,yaml]
217-
----
218-
spring:
219-
liquibase:
220-
change-log: "classpath:/db/changelog/db.changelog-test.yaml"
221-
----
222-
223-
This configures Liquibase to use a different changelog when running in the `test` profile.
224-
225-
Now create the changelog file at `src/test/resources/db/changelog/db.changelog-test.yaml`:
226-
227-
[source,yaml]
228-
----
229-
databaseChangeLog:
230-
- include:
231-
file: classpath:/db/changelog/db.changelog-master.yaml
232-
- changeSet:
233-
runOrder: "last"
234-
id: "test"
235-
changes:
236-
# Insert your changes here
237-
----
238-
239-
This changelog will be used when the tests are run and it will not be packaged in your uber jar or your container.
240-
It includes the production changelog and then declares a new changeset, whose `runOrder: last` setting specifies that it runs after all the production changesets have been run.
241-
You can now use for example the https://docs.liquibase.com/change-types/insert.html[insert changeset] to insert data or the https://docs.liquibase.com/change-types/sql.html[sql changeset] to execute SQL directly.
242-
243-
The last thing to do is to configure Spring Boot to activate the `test` profile when running tests.
244-
To do this, you can add the `@ActiveProfiles("test")` annotation to your javadoc:org.springframework.boot.test.context.SpringBootTest[format=annotation] annotated test classes.
210+
If you want to create Liquibase migrations which populate your test database, you can leverage https://docs.liquibase.com/reference-guide/changelog-attributes/what-are-contexts[Liquibase contexts].
211+
See also the related https://www.liquibase.com/blog/contexts-vs-labels[blog post].
245212

246213

247214

0 commit comments

Comments
 (0)