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

qyzbxkaa  于 2023-05-01  发布在  Kotlin
关注(0)|答案(1)|浏览(102)

我正在使用ktor,exposed和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
omqzjyyz

omqzjyyz1#

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

V1_create_users_table

应该是2 _

V1__create__users__table

相关问题