33 lines
817 B
Kotlin
33 lines
817 B
Kotlin
package be.simplenotes.persistence
|
|
|
|
import be.simplenotes.config.DataSourceConfig
|
|
import be.simplenotes.persistence.utils.DbType
|
|
import be.simplenotes.persistence.utils.type
|
|
import org.flywaydb.core.Flyway
|
|
import javax.inject.Singleton
|
|
import javax.sql.DataSource
|
|
|
|
interface DbMigrations {
|
|
fun migrate()
|
|
}
|
|
|
|
@Singleton
|
|
internal class DbMigrationsImpl(
|
|
private val dataSource: DataSource,
|
|
private val dataSourceConfig: DataSourceConfig,
|
|
) : DbMigrations {
|
|
override fun migrate() {
|
|
|
|
val migrationDir = when (dataSourceConfig.type()) {
|
|
DbType.H2 -> "db/migration/other"
|
|
DbType.MariaDb -> "db/migration/mariadb"
|
|
}
|
|
|
|
Flyway.configure()
|
|
.dataSource(dataSource)
|
|
.locations(migrationDir)
|
|
.load()
|
|
.migrate()
|
|
}
|
|
}
|