Compare commits
15 Commits
dcd23f0283
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
90fcdcaa4f
|
|||
|
d26f0a1310
|
|||
|
e3931e3e8f
|
|||
|
3380f50cc7
|
|||
|
b777eadd13
|
|||
|
bba1f2d63d
|
|||
|
27b335a0af
|
|||
|
21ed1c40b5
|
|||
|
d0c130cb61
|
|||
|
1fbff53dbd
|
|||
|
a759d19466
|
|||
|
8d2efa65df
|
|||
|
0cc1f208ff
|
|||
|
53d857186d
|
|||
|
e74d0cdc60
|
@@ -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 }}
|
||||||
34
README.md
Normal file
34
README.md
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
# migration.ktor
|
||||||
|
|
||||||
|
`migration.ktor` is a Kotlin library that enables code-based migrations in Ktor.
|
||||||
|
|
||||||
|
## 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.2.0")
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
fun Application.configureDatabase() {
|
||||||
|
// connect to a database
|
||||||
|
Database.connect(/* parameters */)
|
||||||
|
|
||||||
|
// install the plugin
|
||||||
|
install(Migration) {
|
||||||
|
// create a migration
|
||||||
|
migration("initial") {
|
||||||
|
// execute code to migrate the database
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -1,55 +1,37 @@
|
|||||||
group = "com.infendro"
|
import com.infendro.plugin.infendro
|
||||||
version = "1.0.2"
|
import com.infendro.plugin.token
|
||||||
|
|
||||||
repositories {
|
group = "com.infendro"
|
||||||
maven("https://git.infendro.com/api/packages/Infendro/maven")
|
version = "1.2.0"
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
|
alias(libs.plugins.infendro)
|
||||||
alias(libs.plugins.kotlin)
|
alias(libs.plugins.kotlin)
|
||||||
id("maven-publish")
|
id("maven-publish")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
infendro()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(libs.ktor.server)
|
implementation(libs.ktor.server)
|
||||||
implementation(libs.exposed)
|
|
||||||
implementation(libs.migration)
|
implementation(libs.migration)
|
||||||
|
implementation(libs.exposed)
|
||||||
|
implementation(libs.exposed.jdbc)
|
||||||
}
|
}
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
create<MavenPublication>("JVM") {
|
create<MavenPublication>("JVM") {
|
||||||
from(components["java"])
|
from(components["java"])
|
||||||
groupId = group as String
|
groupId = project.group as String
|
||||||
artifactId = project.name
|
artifactId = project.name
|
||||||
version = version
|
version = project.version as String
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
infendro(token)
|
||||||
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"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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]
|
[versions]
|
||||||
kotlin = "2.2.10"
|
infendro = "1.1.0"
|
||||||
ktor = "3.2.3"
|
kotlin = "2.3.0"
|
||||||
exposed = "0.61.0"
|
ktor = "3.4.0"
|
||||||
migration = "1.0.0"
|
migration = "1.2.0"
|
||||||
|
exposed = "1.0.0"
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
|
infendro = { id = "com.infendro.plugin", version.ref = "infendro" }
|
||||||
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
|
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
ktor-server = { module = "io.ktor:ktor-server-core-jvm", version.ref = "ktor" }
|
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" }
|
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,22 +1,19 @@
|
|||||||
package com.infendro.ktor.migration
|
package com.infendro.ktor.migration
|
||||||
|
|
||||||
import com.infendro.migration.Config
|
|
||||||
import com.infendro.migration.migrate
|
import com.infendro.migration.migrate
|
||||||
import io.ktor.server.application.*
|
import io.ktor.server.application.*
|
||||||
import org.jetbrains.exposed.sql.Transaction
|
import org.jetbrains.exposed.v1.jdbc.JdbcTransaction
|
||||||
|
|
||||||
val Migration = createApplicationPlugin(
|
val Migration = createApplicationPlugin("Migration", MigrationConfig::new) {
|
||||||
name = "Migration",
|
|
||||||
createConfiguration = { MigrationConfig() },
|
|
||||||
) {
|
|
||||||
migrate(pluginConfig.config)
|
migrate(pluginConfig.config)
|
||||||
}
|
}
|
||||||
|
|
||||||
class MigrationConfig {
|
class MigrationConfig {
|
||||||
internal val config = Config()
|
internal val config = com.infendro.migration.MigrationConfig()
|
||||||
|
|
||||||
fun migration(
|
fun migration(name: String, migrate: JdbcTransaction.() -> Unit) = config.migration(name, migrate)
|
||||||
name: String,
|
|
||||||
migrate: Transaction.() -> Unit,
|
companion object {
|
||||||
) = config.migration(name, migrate)
|
fun new() = MigrationConfig()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user