[英]R2DBC and liquibase
所以開始一個新項目,我想使用 r2dbc 和 webflux,一直在研究有什么支持來處理數據庫遷移。 我在這里能找到的最后一個答案是從 2019 年 7 月開始,liquibase 不支持 R2DBC,在谷歌搜索之后,情況似乎仍然如此。
夢想是在本地開發時使用r2dbc-h2
,然后在生產期間使用類似 postgres 的東西。 Liquibase 將在本地和生產中管理表結構。
一直在嘗試用谷歌搜索一下這種設置的外觀,但那里的信息很少。
我一直在考慮使用liquibase-maven-plugin
設置表,但我不知道這是否適用於r2dbc-h2
。
所以幾個問題:
這對我來說是一個非常黑洞,有任何信息嗎?
我認為在應用程序中使用 2 個驅動程序應該沒有問題。 由於 liquibase 使用標准 jdbc 驅動程序,您可以將其配置為使用該驅動程序進行遷移並配置 r2dbc 以運行應用程序。 也許需要完成一些 tweeks 但我會從以下內容開始:
spring:
liquibase:
url: jdbc:postgresql://localhost:5432/mydb
user: postgres
r2dbc:
url: r2dbc:postgresql://localhost:5432/mydb
username: postgres
並包括兩個庫:
io.r2dbc:r2dbc-postgresql
org.postgresql:postgresql
如果有錯誤,請讓我們發布。
注意:對於測試,您也可以使用 testcontainers 或嵌入式 postgresql
補充@bilak 的答案,您必須將以下依賴項添加到您的 pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
我遇到了同樣的問題,我已經在我的 application.yml 上將屬性user
和URL
添加到 Liquibase 配置中,然后 Spring 開始聲稱大約一個 class 解決了這個問題
從 Spring 啟動 2.6.3 和 Spring 框架 5.3.15 開始,以下配置適用於帶有 Liquibase 的 R2DBC
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-r2dbc'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
//database
implementation "io.r2dbc:r2dbc-postgresql"
runtimeOnly 'org.postgresql:postgresql'
//liquibase
implementation "org.liquibase:liquibase-core"
runtimeOnly 'org.springframework:spring-jdbc'
testImplementation 'io.projectreactor:reactor-test'
}
spring:
main:
web-application-type: REACTIVE
r2dbc:
url: r2dbc:postgresql://localhost/mydb
username: postgres
liquibase:
url: jdbc:postgresql://localhost/mydb
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.