[英]Spring Boot & Liquibase by Example
Spring Boot and MySQL here. Spring Boot和MySQL在这里。 Trying to get my Spring Boot app to use Liquibase for my DB migrations and see in the docs that Spring Boot has built-in support for Liquibase . 试图让我的Spring Boot应用程序使用Liquibase进行数据库迁移,并在文档中看到Spring Boot 内置了对Liquibase的支持 。
However after reading those docs, I'm left with several related concerns: 但是在阅读完这些文档之后,我还有几个相关的问题:
db/changelog/db.changelog-master.yaml
file? db/changelog/db.changelog-master.yaml
文件的基本用途是什么? Is it to store Liquibase configurations (that dictate how Liquibase behaves), or is that where I'm supposed to put the actual, sequential SQL changes (the " migrations ") themselves? 是存储Liquibase配置(指示Liquibase的行为),还是我应该将实际的顺序SQL更改(“ 迁移 ”)本身放在哪里?
src/main/resources/migrations
directory and store my migration changes as individual SQL files, like so: 理想情况下,我希望有一个src/main/resources/migrations
目录,并将我的迁移更改存储为单独的SQL文件,如下所示: src/main/resources/migrations/001-schema.sql
src/main/resources/migrations/002-init.sql
src/main/resources/migrations/003-changing-account-types.sql
The db/changelog/db.changelog-master.yaml
file is the one executed on application startup when using default configuration. db/changelog/db.changelog-master.yaml
文件是在使用默认配置时在应用程序启动时执行的文件。 In that file you can have the sequential SQL changes as well as inclusions to other files. 在该文件中,您可以进行顺序SQL更改以及对其他文件的包含。 For example the file could contain inclusions like this (xml syntax) 例如,该文件可能包含这样的包含(xml语法)
<include file="migrations/001-schema.sql"/>
<include file="migrations/002-init.sql"/>
<include file="migrations/003-changing-account-types.sql"/>
and you would have the configuration you wanted. 你会得到你想要的配置。
About your second question - yes, they are applied at startup. 关于你的第二个问题 - 是的,它们是在启动时应用的。 If it runs on a cluster of nodes, they will each check the status and apply the changes to database if they aren't already applied(the databasechangelog and databasechangelock tables are used for that and they make sure the changes are only applied once) 如果它在节点集群上运行,它们将分别检查状态并将更改应用于数据库(如果尚未应用)(数据库交换日志和数据库交换表用于此目的,并确保更改仅应用一次)
example for yaml syntax yaml语法的示例
databaseChangeLog:
- include:
file: migrations/001-schema.sql
- include:
file: migrations/002-init.sql
- include:
file: migrations/003-changing-account-types.sql
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.