FlywayException:版本只能包含 0..9 和 . (点)。无效版本:1.....) 在 org.flywaydb.core.api.MigrationVersion.toBigInteger:271

问题描述 投票:0回答:2

我正在使用 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
kotlin migration flyway ktor kotlin-exposed
2个回答
0
投票

好吧,这是迁移类命名中的虚拟错误 我有

V1_create_users_table 

应该是 2 _

V1__create__users__table 

0
投票

就我而言,这是由基线版本设置为空(默认)而不是实际版本引起的。

© www.soinside.com 2019 - 2024. All rights reserved.