Add SQL migrations
This commit is contained in:
parent
b87a5c3744
commit
8a6d93c51a
@ -119,7 +119,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.flywaydb</groupId>
|
<groupId>org.flywaydb</groupId>
|
||||||
<artifactId>flyway-core</artifactId>
|
<artifactId>flyway-core</artifactId>
|
||||||
<version>${flyway_version}</version>
|
<version>6.3.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@ -2,9 +2,11 @@ package be.vandewalleh
|
|||||||
|
|
||||||
import be.vandewalleh.controllers.KodeinController
|
import be.vandewalleh.controllers.KodeinController
|
||||||
import be.vandewalleh.controllers.controllerModule
|
import be.vandewalleh.controllers.controllerModule
|
||||||
|
import be.vandewalleh.features.Feature
|
||||||
import be.vandewalleh.features.configurationFeature
|
import be.vandewalleh.features.configurationFeature
|
||||||
import be.vandewalleh.features.configurationModule
|
import be.vandewalleh.features.configurationModule
|
||||||
import be.vandewalleh.features.features
|
import be.vandewalleh.features.features
|
||||||
|
import be.vandewalleh.migrations.Migration
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature
|
import com.fasterxml.jackson.databind.SerializationFeature
|
||||||
import io.ktor.application.Application
|
import io.ktor.application.Application
|
||||||
import io.ktor.application.install
|
import io.ktor.application.install
|
||||||
@ -16,7 +18,9 @@ import io.ktor.locations.Locations
|
|||||||
import io.ktor.routing.routing
|
import io.ktor.routing.routing
|
||||||
import org.kodein.di.Kodein
|
import org.kodein.di.Kodein
|
||||||
import org.kodein.di.description
|
import org.kodein.di.description
|
||||||
|
import org.kodein.di.generic.bind
|
||||||
import org.kodein.di.generic.instance
|
import org.kodein.di.generic.instance
|
||||||
|
import org.kodein.di.generic.singleton
|
||||||
import javax.sql.DataSource
|
import javax.sql.DataSource
|
||||||
|
|
||||||
lateinit var kodein: Kodein
|
lateinit var kodein: Kodein
|
||||||
@ -28,10 +32,15 @@ fun Application.module() {
|
|||||||
kodein = Kodein {
|
kodein = Kodein {
|
||||||
import(controllerModule)
|
import(controllerModule)
|
||||||
import(configurationModule)
|
import(configurationModule)
|
||||||
|
|
||||||
|
bind<Feature>() with singleton { Migration(this.kodein) }
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug(kodein.container.tree.bindings.description())
|
log.debug(kodein.container.tree.bindings.description())
|
||||||
|
|
||||||
|
val feature: Feature by kodein.instance()
|
||||||
|
feature.execute()
|
||||||
|
|
||||||
val controllers: Set<KodeinController> by kodein.instance()
|
val controllers: Set<KodeinController> by kodein.instance()
|
||||||
|
|
||||||
routing {
|
routing {
|
||||||
|
|||||||
@ -1,10 +1,16 @@
|
|||||||
package be.vandewalleh.features
|
package be.vandewalleh.features
|
||||||
|
|
||||||
import io.ktor.application.Application
|
import io.ktor.application.Application
|
||||||
|
import org.kodein.di.Kodein
|
||||||
|
import org.kodein.di.KodeinAware
|
||||||
|
|
||||||
fun Application.features() {
|
fun Application.features() {
|
||||||
locationFeature()
|
locationFeature()
|
||||||
corsFeature()
|
corsFeature()
|
||||||
contentNegotiationFeature()
|
contentNegotiationFeature()
|
||||||
configurationFeature()
|
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