我正在使用 ktor、exclusive 和 mysql 构建 api。我正在尝试使用自动迁移生成,但它会引发错误。
所以在 src/main/db/migration/V1_create_users_table.kt 中
package db.migration
import com.coinypal.features.user.UsersTable
import org.flywaydb.core.api.migration.BaseJavaMigration
import org.flywaydb.core.api.migration.Context
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction
class V1_create_users_table : BaseJavaMigration() {
override fun migrate(context: Context?) {
transaction{
SchemaUtils.create(
UsersTable
)
}
}
}
在应用程序的启动中,我从 DBFactory 运行 init
package com.coinypal.config
import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
import org.flywaydb.core.Flyway
import org.jetbrains.exposed.sql.Database
import javax.sql.DataSource
object DbFactory {
fun init(pool: DataSource) {
Database.connect(pool)
runFlyway(pool)
}
fun init(dbProperties: Env.Datasource) {
val pool = hikari(dbProperties)
Database.connect(pool)
runFlyway(pool)
}
private fun hikari(dbProperties: Env.Datasource): HikariDataSource {
val hikariConfig = HikariConfig().apply {
jdbcUrl = dbProperties.url
username = dbProperties.username
password = dbProperties.password
driverClassName = dbProperties.driver
}
return HikariDataSource(hikariConfig)
}
private fun runFlyway(datasource: DataSource) {
val flyway = Flyway.configure().dataSource(datasource).load()
try {
flyway.info()
flyway.migrate()
} catch (error: Exception) {
throw error
}
}
}
我的数据库依赖项看起来像这样
implementation("org.jetbrains.exposed:exposed-core:$exposed_version")
implementation("org.jetbrains.exposed:exposed-jdbc:$exposed_version")
implementation("org.jetbrains.exposed:exposed-java-time:$exposed_version") //exposed_version=0.38.2
implementation("com.zaxxer:HikariCP:$hikariCp_version")
implementation("org.flywaydb:flyway-core:$flyway_version")
implementation("org.flywaydb:flyway-mysql:$flyway_version") // flyway_version=8.5.13
implementation("mysql:mysql-connector-java:8.0.33")
产生的错误是下一个
(FlywayException: Version may only contain 0..9 and . (dot). Invalid version: 1.create.users.table) at org.flywaydb.core.api.MigrationVersion.toBigInteger:271
好吧,这是迁移类命名中的虚拟错误 我有
V1_create_users_table
应该是 2 _
V1__create__users__table
就我而言,这是由基线版本设置为空(默认)而不是实际版本引起的。