Skip to content

Commit

Permalink
Add tagDatabase change spec, Install komapper-annotation for check da…
Browse files Browse the repository at this point in the history
…tabasechangelog.tag.
  • Loading branch information
momosetkn committed Sep 21, 2024
1 parent d7ec307 commit b98db29
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 1 deletion.
5 changes: 5 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ allprojects {

ktlint {
version.set("1.3.1")
filter {
exclude { entry ->
entry.file.toString() in "generated/"
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,13 @@ class ChangeSetDsl(
changeSetSupport.addChange(change)
}

/**
* We will tag the current state.
* It will be used for rollback.
* [official-document](https://docs.liquibase.com/commands/utility/tag.html)
*
* @param tag name of tag
*/
fun tagDatabase(tag: String) {
val change = changeSetSupport.createChange("tagDatabase") as TagDatabaseChange
change.tag = tag.evalExpressions(changeLog)
Expand Down
19 changes: 19 additions & 0 deletions integration-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ val kotestVersion = rootProject.properties["kotestVersion"] as String
val testcontainersVersion = rootProject.properties["testcontainersVersion"] as String
val komapperVersion = "3.0.0"

plugins {
id("com.google.devtools.ksp") version "2.0.20-1.0.25"
id("org.komapper.gradle") version "3.0.0"
}

dependencies {
implementation(project(":dsl"))
implementation(project(":script-serializer"))
Expand All @@ -20,6 +25,12 @@ dependencies {
// komapper
implementation("org.komapper:komapper-core:$komapperVersion")
implementation("org.komapper:komapper-jdbc:$komapperVersion")
implementation("org.komapper:komapper-annotation:$komapperVersion")
platform("org.komapper:komapper-platform:$komapperVersion").let {
implementation(it)
ksp(it)
}
ksp("org.komapper:komapper-processor")
implementation("org.komapper:komapper-dialect-postgresql-jdbc:$komapperVersion")

// test
Expand All @@ -41,3 +52,11 @@ tasks.test {
useJUnitPlatform()
systemProperty("kotest.framework.classpath.scanning.config.disable", "true")
}

tasks {
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
compilerOptions {
freeCompilerArgs.add("-opt-in=org.komapper.annotation.KomapperExperimentalAssociation")
}
}
}
37 changes: 37 additions & 0 deletions integration-test/src/main/kotlin/komapper/liquibaseEntities.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@file:Suppress("ktlint:standard:filename")

package komapper

import org.komapper.annotation.KomapperColumn
import org.komapper.annotation.KomapperEntity
import org.komapper.annotation.KomapperId
import org.komapper.annotation.KomapperTable
import java.time.LocalDateTime

@KomapperEntity
@KomapperTable(name = "databasechangelog")
data class Databasechangelog(
@KomapperId @KomapperColumn(name = "id") val id: String,
@KomapperColumn(name = "author") val author: String,
@KomapperColumn(name = "filename") val filename: String,
@KomapperColumn(name = "dateexecuted") val dateexecuted: LocalDateTime,
@KomapperColumn(name = "orderexecuted") val orderexecuted: Int,
@KomapperColumn(name = "exectype") val exectype: String,
@KomapperColumn(name = "md5sum") val md5sum: String?,
@KomapperColumn(name = "description") val description: String?,
@KomapperColumn(name = "comments") val comments: String?,
@KomapperColumn(name = "tag") val tag: String?,
@KomapperColumn(name = "liquibase") val liquibase: String?,
@KomapperColumn(name = "contexts") val contexts: String?,
@KomapperColumn(name = "labels") val labels: String?,
@KomapperColumn(name = "deployment_id") val deploymentId: String?
)

@KomapperEntity
@KomapperTable(name = "databasechangeloglock")
data class Databasechangeloglock(
@KomapperId @KomapperColumn(name = "id") val id: Int,
@KomapperColumn(name = "locked") val locked: Boolean,
@KomapperColumn(name = "lockgranted") val lockgranted: LocalDateTime?,
@KomapperColumn(name = "lockedby") val lockedby: String?
)
23 changes: 22 additions & 1 deletion integration-test/src/test/kotlin/momosetkn/ChangeSetSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ package momosetkn

import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import komapper.databasechangelog
import momosetkn.liquibase.client.LiquibaseClient
import momosetkn.utils.DDLUtils.shouldBeEqualDdl
import momosetkn.utils.Database
import momosetkn.utils.DatabaseKomapperExtensions.komapperDb
import momosetkn.utils.InterchangeableChangeLog
import momosetkn.utils.set
import org.komapper.core.dsl.Meta
import org.komapper.core.dsl.QueryDsl

class ChangeSetSpec : FunSpec({
beforeEach {
Expand Down Expand Up @@ -41,7 +46,6 @@ class ChangeSetSpec : FunSpec({
timeout = "10s"
) {
arg("ps")
// arg("-h")
}
}
}
Expand Down Expand Up @@ -185,4 +189,21 @@ class ChangeSetSpec : FunSpec({
)
}
}
context("tagDatabase") {
InterchangeableChangeLog.set {
changeSet(author = "user", id = "100") {
tagDatabase("example_tag1")
}
}
test("can migrate") {
subject()
val db = Database.komapperDb()
val d = Meta.databasechangelog
val results = db.runQuery {
QueryDsl.from(d)
}
results.size shouldBe 1
results[0].tag shouldBe "example_tag1"
}
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package momosetkn.utils

import org.komapper.jdbc.JdbcDatabase

object DatabaseKomapperExtensions {
fun Database.komapperDb() = JdbcDatabase(
url = this.startedContainer.jdbcUrl,
user = this.startedContainer.username,
password = this.startedContainer.password,
)
}

0 comments on commit b98db29

Please sign in to comment.