I am building api with ktor, exposed and mysql. I am trying to use automated migration generation, but it throws an error.
so in 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
)
}
}
}
in the start of the app I am running init from my DBFactory
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
}
}
}
my db dependencies look like this
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")
the resulting error is next
(FlywayException: Version may only contain 0..9 and . (dot). Invalid version: 1.create.users.table) at org.flywaydb.core.api.MigrationVersion.toBigInteger:271
okay so it was dummy error in naming of migration class I had
V1_create_users_table
and it should have been with 2 _
V1__create__users__table