Compare commits
3 Commits
dcd23f0283
...
0cc1f208ff
| Author | SHA1 | Date | |
|---|---|---|---|
|
0cc1f208ff
|
|||
|
53d857186d
|
|||
|
e74d0cdc60
|
44
README.md
Normal file
44
README.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# Ktor Plugin for Database Migration
|
||||
|
||||
This plugin enables code-based database migrations in Ktor using [Kotlin Database Migration](https://git.infendro.com/Infendro/kotlin-migration).
|
||||
|
||||
## Installation
|
||||
|
||||
Add the following to your `build.gradle.kts`.
|
||||
|
||||
```kotlin
|
||||
repositories {
|
||||
maven("https://git.infendro.com/api/packages/Infendro/maven")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("com.infendro:ktor-migration:1.1.0")
|
||||
}
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```kotlin
|
||||
import com.infendro.ktor.migration.Migration
|
||||
import io.ktor.server.application.*
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
|
||||
fun Application.configureDatabase() {
|
||||
// connect to a database
|
||||
Database.connect(/* ... */)
|
||||
|
||||
// install the plugin
|
||||
install(Migration) {
|
||||
// create a migration
|
||||
migration("initial") {
|
||||
// execute code to migrate the database
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## How It Works
|
||||
|
||||
* Each migration is identified by a unique name.
|
||||
* Migrations are executed in the order they are declared in.
|
||||
* Executed migrations are tracked in a database table and skipped on subsequent runs.
|
||||
@@ -1,5 +1,5 @@
|
||||
group = "com.infendro"
|
||||
version = "1.0.2"
|
||||
version = "1.1.0"
|
||||
|
||||
repositories {
|
||||
maven("https://git.infendro.com/api/packages/Infendro/maven")
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
kotlin = "2.2.10"
|
||||
ktor = "3.2.3"
|
||||
exposed = "0.61.0"
|
||||
migration = "1.0.0"
|
||||
migration = "1.1.0"
|
||||
|
||||
[plugins]
|
||||
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.infendro.migration.migrate
|
||||
import io.ktor.server.application.*
|
||||
import org.jetbrains.exposed.sql.Transaction
|
||||
|
||||
@Suppress("UNUSED")
|
||||
val Migration = createApplicationPlugin(
|
||||
name = "Migration",
|
||||
createConfiguration = { MigrationConfig() },
|
||||
@@ -15,6 +16,7 @@ val Migration = createApplicationPlugin(
|
||||
class MigrationConfig {
|
||||
internal val config = Config()
|
||||
|
||||
@Suppress("UNUSED")
|
||||
fun migration(
|
||||
name: String,
|
||||
migrate: Transaction.() -> Unit,
|
||||
|
||||
Reference in New Issue
Block a user