Compare commits
12 Commits
0cc1f208ff
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
90fcdcaa4f
|
|||
|
d26f0a1310
|
|||
|
e3931e3e8f
|
|||
|
3380f50cc7
|
|||
|
b777eadd13
|
|||
|
bba1f2d63d
|
|||
|
27b335a0af
|
|||
|
21ed1c40b5
|
|||
|
d0c130cb61
|
|||
|
1fbff53dbd
|
|||
|
a759d19466
|
|||
|
8d2efa65df
|
@@ -1,34 +0,0 @@
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
env:
|
||||
GIT__TOKEN: ${{ secrets.TOKEN }}
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: linux
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/cache/restore@v4
|
||||
with:
|
||||
key: gradle
|
||||
path: |
|
||||
~/.gradle/caches/
|
||||
~/.gradle/wrapper/
|
||||
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '24'
|
||||
distribution: 'temurin'
|
||||
|
||||
- run: ./gradlew publish
|
||||
|
||||
- uses: actions/cache/save@v4
|
||||
with:
|
||||
key: gradle
|
||||
path: |
|
||||
~/.gradle/caches/
|
||||
~/.gradle/wrapper/
|
||||
30
.gitea/workflows/publish.yaml
Normal file
30
.gitea/workflows/publish.yaml
Normal file
@@ -0,0 +1,30 @@
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: linux
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '24'
|
||||
distribution: 'temurin'
|
||||
|
||||
- name: Cache Gradle
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
key: gradle-${{ hashFiles('**/libs.versions.toml') }}
|
||||
restore-keys: gradle
|
||||
path: |
|
||||
~/.gradle/caches/
|
||||
~/.gradle/wrapper/
|
||||
|
||||
- name: Publish
|
||||
run: ./gradlew publish
|
||||
env:
|
||||
INFENDRO__TOKEN: ${{ secrets.TOKEN }}
|
||||
18
README.md
18
README.md
@@ -1,6 +1,6 @@
|
||||
# Ktor Plugin for Database Migration
|
||||
# migration.ktor
|
||||
|
||||
This plugin enables code-based database migrations in Ktor using [Kotlin Database Migration](https://git.infendro.com/Infendro/kotlin-migration).
|
||||
`migration.ktor` is a Kotlin library that enables code-based migrations in Ktor.
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -12,20 +12,16 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("com.infendro:ktor-migration:1.1.0")
|
||||
implementation("com.infendro:ktor-migration:1.2.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(/* ... */)
|
||||
Database.connect(/* parameters */)
|
||||
|
||||
// install the plugin
|
||||
install(Migration) {
|
||||
@@ -36,9 +32,3 @@ fun Application.configureDatabase() {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 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,55 +1,37 @@
|
||||
group = "com.infendro"
|
||||
version = "1.1.0"
|
||||
import com.infendro.plugin.infendro
|
||||
import com.infendro.plugin.token
|
||||
|
||||
repositories {
|
||||
maven("https://git.infendro.com/api/packages/Infendro/maven")
|
||||
mavenCentral()
|
||||
}
|
||||
group = "com.infendro"
|
||||
version = "1.2.0"
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.infendro)
|
||||
alias(libs.plugins.kotlin)
|
||||
id("maven-publish")
|
||||
}
|
||||
|
||||
repositories {
|
||||
infendro()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.ktor.server)
|
||||
implementation(libs.exposed)
|
||||
implementation(libs.migration)
|
||||
implementation(libs.exposed)
|
||||
implementation(libs.exposed.jdbc)
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("JVM") {
|
||||
from(components["java"])
|
||||
groupId = group as String
|
||||
groupId = project.group as String
|
||||
artifactId = project.name
|
||||
version = version
|
||||
version = project.version as String
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
maven {
|
||||
url = uri("https://git.infendro.com/api/packages/Infendro/maven")
|
||||
authentication.create("header", HttpHeaderAuthentication::class)
|
||||
credentials(HttpHeaderCredentials::class) {
|
||||
val token = secret("git.token") ?: throw GradleException()
|
||||
|
||||
name = "Authorization"
|
||||
value = "token $token"
|
||||
}
|
||||
}
|
||||
infendro(token)
|
||||
}
|
||||
}
|
||||
|
||||
fun secret(
|
||||
key: String,
|
||||
): String? {
|
||||
val property = key
|
||||
val environment = key
|
||||
.uppercase()
|
||||
.replace(".", "__")
|
||||
|
||||
val prop = properties[property] as String?
|
||||
val env = System.getenv(environment)
|
||||
|
||||
return prop ?: env
|
||||
}
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
[versions]
|
||||
kotlin = "2.2.10"
|
||||
ktor = "3.2.3"
|
||||
exposed = "0.61.0"
|
||||
migration = "1.1.0"
|
||||
infendro = "1.1.0"
|
||||
kotlin = "2.3.0"
|
||||
ktor = "3.4.0"
|
||||
migration = "1.2.0"
|
||||
exposed = "1.0.0"
|
||||
|
||||
[plugins]
|
||||
infendro = { id = "com.infendro.plugin", version.ref = "infendro" }
|
||||
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
|
||||
|
||||
[libraries]
|
||||
ktor-server = { module = "io.ktor:ktor-server-core-jvm", version.ref = "ktor" }
|
||||
|
||||
exposed = { module = "org.jetbrains.exposed:exposed-core", version.ref = "exposed" }
|
||||
migration = { module = "com.infendro:migration", version.ref = "migration" }
|
||||
exposed = { module = "org.jetbrains.exposed:exposed-core", version.ref = "exposed" }
|
||||
exposed-jdbc = { module = "org.jetbrains.exposed:exposed-jdbc", version.ref = "exposed" }
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
rootProject.name = "ktor-migration"
|
||||
rootProject.name = "migration-ktor"
|
||||
|
||||
pluginManagement.repositories {
|
||||
maven("https://git.infendro.com/api/packages/Infendro/maven")
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
@@ -1,24 +1,19 @@
|
||||
package com.infendro.ktor.migration
|
||||
|
||||
import com.infendro.migration.Config
|
||||
import com.infendro.migration.migrate
|
||||
import io.ktor.server.application.*
|
||||
import org.jetbrains.exposed.sql.Transaction
|
||||
import org.jetbrains.exposed.v1.jdbc.JdbcTransaction
|
||||
|
||||
@Suppress("UNUSED")
|
||||
val Migration = createApplicationPlugin(
|
||||
name = "Migration",
|
||||
createConfiguration = { MigrationConfig() },
|
||||
) {
|
||||
val Migration = createApplicationPlugin("Migration", MigrationConfig::new) {
|
||||
migrate(pluginConfig.config)
|
||||
}
|
||||
|
||||
class MigrationConfig {
|
||||
internal val config = Config()
|
||||
internal val config = com.infendro.migration.MigrationConfig()
|
||||
|
||||
@Suppress("UNUSED")
|
||||
fun migration(
|
||||
name: String,
|
||||
migrate: Transaction.() -> Unit,
|
||||
) = config.migration(name, migrate)
|
||||
fun migration(name: String, migrate: JdbcTransaction.() -> Unit) = config.migration(name, migrate)
|
||||
|
||||
companion object {
|
||||
fun new() = MigrationConfig()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user