Merge pull request '1.2.0 release' (#2) from develop into main
All checks were successful
/ publish (push) Successful in 1m15s
All checks were successful
/ publish (push) Successful in 1m15s
Reviewed-on: Infendro/migration-kt#2
This commit was merged in pull request #2.
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
env:
|
||||
INFENDRO__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 }}
|
||||
@@ -12,16 +12,13 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("com.infendro:migration:1.1.1")
|
||||
implementation("com.infendro:migration:1.2.0")
|
||||
}
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```kotlin
|
||||
import com.infendro.migration.migrate
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
|
||||
fun configureDatabase() {
|
||||
// connect to a database
|
||||
Database.connect(/* parameters */)
|
||||
|
||||
@@ -2,7 +2,7 @@ import com.infendro.plugin.infendro
|
||||
import com.infendro.plugin.token
|
||||
|
||||
group = "com.infendro"
|
||||
version = "1.1.1"
|
||||
version = "1.2.0"
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.infendro)
|
||||
@@ -17,6 +17,7 @@ repositories {
|
||||
dependencies {
|
||||
implementation(libs.exposed)
|
||||
implementation(libs.exposed.dao)
|
||||
implementation(libs.exposed.jdbc)
|
||||
}
|
||||
|
||||
publishing {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[versions]
|
||||
infendro = "1.0.0"
|
||||
kotlin = "2.2.10"
|
||||
exposed = "0.61.0"
|
||||
infendro = "1.1.0"
|
||||
kotlin = "2.3.0"
|
||||
exposed = "1.0.0"
|
||||
|
||||
[plugins]
|
||||
infendro = { id = "com.infendro.plugin", version.ref = "infendro" }
|
||||
@@ -10,3 +10,4 @@ kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
|
||||
[libraries]
|
||||
exposed = { module = "org.jetbrains.exposed:exposed-core", version.ref = "exposed" }
|
||||
exposed-dao = { module = "org.jetbrains.exposed:exposed-dao", version.ref = "exposed" }
|
||||
exposed-jdbc = { module = "org.jetbrains.exposed:exposed-jdbc", version.ref = "exposed" }
|
||||
|
||||
@@ -3,9 +3,9 @@ package com.infendro.migration
|
||||
import com.infendro.migration.exception.DuplicateMigrationException
|
||||
import com.infendro.migration.model.MigrationRepository
|
||||
import com.infendro.migration.model.MigrationTable
|
||||
import org.jetbrains.exposed.sql.SchemaUtils
|
||||
import org.jetbrains.exposed.sql.Transaction
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import org.jetbrains.exposed.v1.jdbc.JdbcTransaction
|
||||
import org.jetbrains.exposed.v1.jdbc.SchemaUtils
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
@@ -14,10 +14,7 @@ internal val logger: Logger = LoggerFactory.getLogger("Database")
|
||||
class MigrationConfig {
|
||||
internal val migrations: MutableList<Migration> = mutableListOf()
|
||||
|
||||
fun migration(
|
||||
name: String,
|
||||
migrate: Transaction.() -> Unit,
|
||||
) {
|
||||
fun migration(name: String, migrate: JdbcTransaction.() -> Unit) {
|
||||
if (migrations.any { it.name == name })
|
||||
throw DuplicateMigrationException(name)
|
||||
|
||||
@@ -26,13 +23,11 @@ class MigrationConfig {
|
||||
|
||||
data class Migration(
|
||||
val name: String,
|
||||
val migrate: Transaction.() -> Unit,
|
||||
val migrate: JdbcTransaction.() -> Unit,
|
||||
)
|
||||
}
|
||||
|
||||
fun migrate(
|
||||
config: MigrationConfig,
|
||||
) {
|
||||
fun migrate(config: MigrationConfig) {
|
||||
transaction {
|
||||
SchemaUtils.create(MigrationTable)
|
||||
}
|
||||
@@ -41,23 +36,19 @@ fun migrate(
|
||||
if (MigrationRepository.exists(name))
|
||||
continue
|
||||
|
||||
transaction {
|
||||
try {
|
||||
migrate()
|
||||
logger.info("""Migration "$name" successful""")
|
||||
} catch (e: Exception) {
|
||||
logger.error("""Migration "$name" failed""")
|
||||
throw e
|
||||
}
|
||||
try {
|
||||
transaction { migrate() }
|
||||
logger.info("""Migration "$name" successful""")
|
||||
} catch (e: Exception) {
|
||||
logger.error("""Migration "$name" failed""")
|
||||
throw e
|
||||
}
|
||||
|
||||
MigrationRepository.insert(name)
|
||||
}
|
||||
}
|
||||
|
||||
fun migrate(
|
||||
configure: MigrationConfig.() -> Unit,
|
||||
) {
|
||||
fun migrate(configure: MigrationConfig.() -> Unit) {
|
||||
val config = MigrationConfig()
|
||||
config.configure()
|
||||
migrate(config)
|
||||
|
||||
@@ -2,4 +2,7 @@ package com.infendro.migration.exception
|
||||
|
||||
class DuplicateMigrationException(
|
||||
val name: String,
|
||||
) : Exception()
|
||||
) : Exception() {
|
||||
override val message: String
|
||||
get() = """duplicate migration "$name""""
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.infendro.migration.model
|
||||
|
||||
import org.jetbrains.exposed.dao.LongEntity
|
||||
import org.jetbrains.exposed.dao.LongEntityClass
|
||||
import org.jetbrains.exposed.dao.id.EntityID
|
||||
import org.jetbrains.exposed.dao.id.LongIdTable
|
||||
import org.jetbrains.exposed.v1.core.dao.id.EntityID
|
||||
import org.jetbrains.exposed.v1.core.dao.id.LongIdTable
|
||||
import org.jetbrains.exposed.v1.dao.LongEntity
|
||||
import org.jetbrains.exposed.v1.dao.LongEntityClass
|
||||
|
||||
object MigrationTable : LongIdTable("migration", "id") {
|
||||
val name = text("name")
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
package com.infendro.migration.model
|
||||
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import org.jetbrains.exposed.v1.core.eq
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
|
||||
object MigrationRepository {
|
||||
fun exists(
|
||||
name: String,
|
||||
): Boolean = transaction {
|
||||
fun exists(name: String): Boolean = transaction {
|
||||
MigrationEntity
|
||||
.find { MigrationTable.name eq name }
|
||||
.any()
|
||||
}
|
||||
|
||||
fun insert(
|
||||
name: String,
|
||||
): Unit = transaction {
|
||||
fun insert(name: String): Unit = transaction {
|
||||
MigrationEntity
|
||||
.new { this.name = name }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user