Add SQL migrations
This commit is contained in:
parent
b87a5c3744
commit
8a6d93c51a
@ -119,7 +119,7 @@
|
||||
<dependency>
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-core</artifactId>
|
||||
<version>${flyway_version}</version>
|
||||
<version>6.3.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
||||
@ -2,9 +2,11 @@ package be.vandewalleh
|
||||
|
||||
import be.vandewalleh.controllers.KodeinController
|
||||
import be.vandewalleh.controllers.controllerModule
|
||||
import be.vandewalleh.features.Feature
|
||||
import be.vandewalleh.features.configurationFeature
|
||||
import be.vandewalleh.features.configurationModule
|
||||
import be.vandewalleh.features.features
|
||||
import be.vandewalleh.migrations.Migration
|
||||
import com.fasterxml.jackson.databind.SerializationFeature
|
||||
import io.ktor.application.Application
|
||||
import io.ktor.application.install
|
||||
@ -16,7 +18,9 @@ import io.ktor.locations.Locations
|
||||
import io.ktor.routing.routing
|
||||
import org.kodein.di.Kodein
|
||||
import org.kodein.di.description
|
||||
import org.kodein.di.generic.bind
|
||||
import org.kodein.di.generic.instance
|
||||
import org.kodein.di.generic.singleton
|
||||
import javax.sql.DataSource
|
||||
|
||||
lateinit var kodein: Kodein
|
||||
@ -28,10 +32,15 @@ fun Application.module() {
|
||||
kodein = Kodein {
|
||||
import(controllerModule)
|
||||
import(configurationModule)
|
||||
|
||||
bind<Feature>() with singleton { Migration(this.kodein) }
|
||||
}
|
||||
|
||||
log.debug(kodein.container.tree.bindings.description())
|
||||
|
||||
val feature: Feature by kodein.instance()
|
||||
feature.execute()
|
||||
|
||||
val controllers: Set<KodeinController> by kodein.instance()
|
||||
|
||||
routing {
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package be.vandewalleh.features
|
||||
|
||||
import io.ktor.application.Application
|
||||
import org.kodein.di.Kodein
|
||||
import org.kodein.di.KodeinAware
|
||||
|
||||
fun Application.features() {
|
||||
locationFeature()
|
||||
@ -8,3 +10,7 @@ fun Application.features() {
|
||||
contentNegotiationFeature()
|
||||
configurationFeature()
|
||||
}
|
||||
|
||||
abstract class Feature(override val kodein: Kodein) : KodeinAware {
|
||||
abstract fun execute(): Unit
|
||||
}
|
||||
20
api/src/migrations/Migration.kt
Normal file
20
api/src/migrations/Migration.kt
Normal file
@ -0,0 +1,20 @@
|
||||
package be.vandewalleh.migrations
|
||||
|
||||
import be.vandewalleh.features.Feature
|
||||
import org.flywaydb.core.Flyway
|
||||
import org.kodein.di.Kodein
|
||||
import org.kodein.di.generic.instance
|
||||
import javax.sql.DataSource
|
||||
|
||||
class Migration(override val kodein: Kodein) : Feature(kodein) {
|
||||
|
||||
override fun execute() {
|
||||
val dataSource by instance<DataSource>()
|
||||
val flyway = Flyway.configure()
|
||||
.dataSource(dataSource)
|
||||
.baselineOnMigrate(true)
|
||||
.load()
|
||||
flyway.migrate()
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user