我正在尝试手动运行 Flyway 迁移,而不是在应用程序启动时运行,使用以下参考 - https://documentation.red-gate.com/fd/gradle-task-184127407.html
在 build.gradle 中我添加了以下依赖项
plugins {
id("org.flywaydb.flyway") version "11.0.1"
}
应用程序属性
datasources.default.url=jdbc:postgresql://localhost:5432/school_staff
datasources.default.username=keycloak
datasources.default.password=password
datasources.default.dialect=POSTGRES
datasources.default.driver-class-name=org.postgresql.Driver
datasources.default.schema-generate=NONE
flyway.datasources.default.enabled=false
在
resources
-> db
-> migration
下,我将以下迁移作为 V1__Initial__Migration
CREATE TABLE tag
(
id UUID NOT NULL,
name VARCHAR(255),
CONSTRAINT pk_tag PRIMARY KEY (id)
);
从 Gradle 插件的文档中我必须添加以下配置
flyway {
url = "jdbc:postgresql://localhost:5432/school_staff"
user = "keycloak"
password = "password"
locations = arrayOf("classpath:db/migration")
baselineOnMigrate = true
}
// Ensure classes are built before migration
tasks.named("flywayMigrate").configure {
dependsOn(tasks.named("classes"))
}
当我运行
./gradlew flywayMigration
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':flywayMigrate'.
> Error occurred while executing flywayMigrate
No database found to handle jdbc:postgresql://localhost:5432/school_staff
如何使用 application.properties 中的数据源
datasources.default.url
唯一有效的方法是将构建脚本放在文件顶部
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.flywaydb:flyway-database-postgresql:11.1.0")
}
}