有没有一种简单的方法可以在部署时隔离Liquibase执行的上下文?
•浏览 1
Is there a simple way to isolate context for Liquibase execution on deployment?
我正在为将使用 Spring Boot 的新服务定义架构。我正在寻找一种方法来配置 Liquibase 部署以仅在某个配置文件处于活动状态时执行。如果可能,我还想禁用所有其他组件,以避免在数据库部署完成之前来自服务逻辑的操作。
我已成功启动我的服务,并看到我的变更集执行。除了对所有组件进行极端配置文件操作之外,我不确定其他方法可以使我的 Liquibase 配置文件成为独立执行,避免在应用程序上下文中实例化组件。
这是我的配置:
spring:
application:
name: liquibase-spring-postgres-example
liquibase:
enabled: false
---
spring:
profiles: dev
datasource:
username: ${service_user}
password: ${DATASOURCE_DB_PASS}
url: jdbc:postgresql://{db}:{port}/schema
liquibase:
url: jdbc:postgresql://{db}:{port}/schema
---
spring:
profiles: liquibase
datasource:
## provided to get spring boot to start up
url: jdbc:postgresql://{db}:{port}/schema
liquibase:
user: ${liquibase_user}
password: ${LIQUIBASE_DB_PASS}
contexts: release
enabled: truespring:
...
main:
web-application-type: nonejava -cp /path/to/spring-boot-fat.jar \\
-Dloader.system=true \\
-Dloader.main=liquibase.integration.commandline.Main \\
org.springframework.boot.loader.PropertiesLauncher \\
--changeLogFile=db/changelog/db-changelog-master.xml \\
--driver=org.h2.Driver \\
--url="jdbc:h2:~/h2db/liquibase-test;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE" \\
--password=sa \\
--username=sa \\
updateSQL
我已经尝试在我在这里找到的评论的帮助下成功禁用嵌入式码头服务器之类的东西:
spring:
application:
name: liquibase-spring-postgres-example
liquibase:
enabled: false
---
spring:
profiles: dev
datasource:
username: ${service_user}
password: ${DATASOURCE_DB_PASS}
url: jdbc:postgresql://{db}:{port}/schema
liquibase:
url: jdbc:postgresql://{db}:{port}/schema
---
spring:
profiles: liquibase
datasource:
## provided to get spring boot to start up
url: jdbc:postgresql://{db}:{port}/schema
liquibase:
user: ${liquibase_user}
password: ${LIQUIBASE_DB_PASS}
contexts: release
enabled: truespring:
...
main:
web-application-type: nonejava -cp /path/to/spring-boot-fat.jar \\
-Dloader.system=true \\
-Dloader.main=liquibase.integration.commandline.Main \\
org.springframework.boot.loader.PropertiesLauncher \\
--changeLogFile=db/changelog/db-changelog-master.xml \\
--driver=org.h2.Driver \\
--url="jdbc:h2:~/h2db/liquibase-test;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE" \\
--password=sa \\
--username=sa \\
updateSQL
除了所有 bean 的极端配置文件定义之外,是否还有其他方法,或者在 Spring Boot 之外手动运行 Liquibase 来实现这一点?
要对 spring-boot jar 文件执行脚本,这样的东西应该可以帮助你:
spring:
application:
name: liquibase-spring-postgres-example
liquibase:
enabled: false
---
spring:
profiles: dev
datasource:
username: ${service_user}
password: ${DATASOURCE_DB_PASS}
url: jdbc:postgresql://{db}:{port}/schema
liquibase:
url: jdbc:postgresql://{db}:{port}/schema
---
spring:
profiles: liquibase
datasource:
## provided to get spring boot to start up
url: jdbc:postgresql://{db}:{port}/schema
liquibase:
user: ${liquibase_user}
password: ${LIQUIBASE_DB_PASS}
contexts: release
enabled: truespring:
...
main:
web-application-type: nonejava -cp /path/to/spring-boot-fat.jar \\
-Dloader.system=true \\
-Dloader.main=liquibase.integration.commandline.Main \\
org.springframework.boot.loader.PropertiesLauncher \\
--changeLogFile=db/changelog/db-changelog-master.xml \\
--driver=org.h2.Driver \\
--url="jdbc:h2:~/h2db/liquibase-test;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE" \\
--password=sa \\
--username=sa \\
updateSQL
edit:这是针对 spring-boot 1.5.x 测试的,但我想它也应该针对 2.x 工作。