-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from momosetkn/feat/custom-jooq-change
add custom-jooq-change module
- Loading branch information
Showing
42 changed files
with
797 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
val liquibaseVersion = rootProject.properties["liquibaseVersion"] as String | ||
val kotestVersion = rootProject.properties["kotestVersion"] as String | ||
val liquibaseKotlinVersion = rootProject.properties["liquibaseKotlinVersion"] as String | ||
val kotlinVersion = rootProject.properties["kotlinVersion"] as String | ||
|
||
dependencies { | ||
implementation(project(":dsl")) | ||
// liquibase | ||
implementation("org.liquibase:liquibase-core:$liquibaseVersion") | ||
// reflection | ||
api("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion") | ||
|
||
// test | ||
testImplementation("io.kotest:kotest-framework-engine-jvm:$kotestVersion") | ||
testImplementation("io.kotest:kotest-runner-junit5:$kotestVersion") | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
systemProperty("kotest.framework.classpath.scanning.config.disable", "true") | ||
} |
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
...c/main/kotlin/momosetkn/liquibase/kotlin/change/custom/komapper/ChangeSetDslExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package momosetkn.liquibase.kotlin.change.custom.komapper | ||
|
||
import liquibase.change.custom.CustomChange | ||
import liquibase.change.custom.CustomChangeWrapper | ||
import liquibase.change.custom.setCustomChange | ||
import momosetkn.liquibase.kotlin.dsl.ChangeSetDsl | ||
|
||
fun ChangeSetDsl.addCustomChange(change: CustomChange) { | ||
val customChangeWrapper = this.changeSetSupport.createChange("customChange") as CustomChangeWrapper | ||
customChangeWrapper.setCustomChange(change) | ||
changeSetSupport.addChange(customChangeWrapper) | ||
} |
10 changes: 2 additions & 8 deletions
10
...base/kotlin/change/KomapperJdbcContext.kt → ...m/komapper/ConvertToJavaxSqlDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
val liquibaseVersion = rootProject.properties["liquibaseVersion"] as String | ||
val kotestVersion = rootProject.properties["kotestVersion"] as String | ||
val liquibaseKotlinVersion = rootProject.properties["liquibaseKotlinVersion"] as String | ||
val kotlinVersion = rootProject.properties["kotlinVersion"] as String | ||
val jooqVersion = rootProject.properties["jooqVersion"] as String | ||
|
||
dependencies { | ||
implementation(project(":dsl")) | ||
implementation(project(":script-parser")) | ||
api(project(":custom-change-core")) | ||
// liquibase | ||
implementation("org.liquibase:liquibase-core:$liquibaseVersion") | ||
// jooq | ||
implementation("org.jooq:jooq:$jooqVersion") | ||
// reflection | ||
api("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion") | ||
|
||
// test | ||
testImplementation("io.kotest:kotest-framework-engine-jvm:$kotestVersion") | ||
testImplementation("io.kotest:kotest-runner-junit5:$kotestVersion") | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
systemProperty("kotest.framework.classpath.scanning.config.disable", "true") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" ?> | ||
<SmellBaseline> | ||
<ManuallySuppressedIssues></ManuallySuppressedIssues> | ||
<CurrentIssues> | ||
<ID>ForbiddenComment:RollbackTaskCustomJooqChange.kt$RollbackTaskCustomJooqChange$// FIXME: CustomTaskRollback has a bug that causes it to be rolled back twice, but there is a workaround.</ID> | ||
</CurrentIssues> | ||
</SmellBaseline> |
10 changes: 10 additions & 0 deletions
10
...ain/kotlin/momosetkn/liquibase/kotlin/change/custom/jooq/CustomJooqChangeParserImports.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package momosetkn.liquibase.kotlin.change.custom.jooq | ||
|
||
import momosetkn.liquibase.kotlin.parser.KotlinScriptParserImports | ||
|
||
class CustomJooqChangeParserImports : KotlinScriptParserImports { | ||
override fun imports() = listOf( | ||
"momosetkn.liquibase.kotlin.change.custom.jooq.customJooqChange", | ||
"org.jooq.core.dsl.QueryDsl", | ||
) | ||
} |
30 changes: 30 additions & 0 deletions
30
...nge/src/main/kotlin/momosetkn/liquibase/kotlin/change/custom/jooq/CustomJooqJdbcChange.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package momosetkn.liquibase.kotlin.change.custom.jooq | ||
|
||
import liquibase.exception.ValidationErrors | ||
import momosetkn.liquibase.kotlin.change.custom.komapper.addCustomChange | ||
import momosetkn.liquibase.kotlin.dsl.ChangeSetDsl | ||
|
||
fun ChangeSetDsl.customJooqChange( | ||
confirmationMessage: String = "Executed CustomJooqChange.", | ||
rollback: ((org.jooq.DSLContext) -> Unit)? = null, | ||
validate: (org.jooq.DSLContext) -> ValidationErrors = { ValidationErrors() }, | ||
execute: (org.jooq.DSLContext) -> Unit, | ||
) { | ||
val change = if (rollback != null) { | ||
val define = CustomRollbackableTaskChangeDefineImpl( | ||
execute, | ||
validate, | ||
rollback, | ||
confirmationMessage, | ||
) | ||
RollbackTaskCustomJooqChange(define) | ||
} else { | ||
val define = CustomTaskChangeDefineImpl( | ||
execute, | ||
validate, | ||
confirmationMessage, | ||
) | ||
ForwardOnlyTaskCustomJooqChange(define) | ||
} | ||
addCustomChange(change) | ||
} |
18 changes: 18 additions & 0 deletions
18
...in/kotlin/momosetkn/liquibase/kotlin/change/custom/jooq/CustomKomapperJdbcChangeDefine.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package momosetkn.liquibase.kotlin.change.custom.jooq | ||
|
||
import liquibase.exception.ValidationErrors | ||
|
||
sealed interface CustomTaskChangeDefine | ||
|
||
data class CustomTaskChangeDefineImpl( | ||
val executeBlock: (org.jooq.DSLContext) -> Unit, | ||
val validateBlock: (org.jooq.DSLContext) -> ValidationErrors, | ||
val confirmationMessage: String, | ||
) : CustomTaskChangeDefine | ||
|
||
data class CustomRollbackableTaskChangeDefineImpl( | ||
val executeBlock: (org.jooq.DSLContext) -> Unit, | ||
val validateBlock: (org.jooq.DSLContext) -> ValidationErrors, | ||
val rollbackBlock: (org.jooq.DSLContext) -> Unit, | ||
val confirmationMessage: String, | ||
) : CustomTaskChangeDefine |
30 changes: 30 additions & 0 deletions
30
...n/kotlin/momosetkn/liquibase/kotlin/change/custom/jooq/ForwardOnlyTaskCustomJooqChange.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package momosetkn.liquibase.kotlin.change.custom.jooq | ||
|
||
import liquibase.change.custom.CustomChange | ||
import liquibase.change.custom.CustomTaskChange | ||
import liquibase.database.Database | ||
import liquibase.exception.ValidationErrors | ||
import liquibase.resource.ResourceAccessor | ||
|
||
class ForwardOnlyTaskCustomJooqChange( | ||
private val define: CustomTaskChangeDefineImpl, | ||
) : CustomChange, CustomTaskChange { | ||
private var resourceAccessor: ResourceAccessor? = null | ||
override fun getConfirmationMessage(): String { | ||
return define.confirmationMessage | ||
} | ||
|
||
override fun setUp() = Unit | ||
|
||
override fun setFileOpener(resourceAccessor: ResourceAccessor) { | ||
this.resourceAccessor = resourceAccessor | ||
} | ||
|
||
override fun validate(database: Database): ValidationErrors { | ||
return define.validateBlock(database.toJooqDSLContext()) | ||
} | ||
|
||
override fun execute(database: Database) { | ||
define.executeBlock(database.toJooqDSLContext()) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ange/src/main/kotlin/momosetkn/liquibase/kotlin/change/custom/jooq/KomapperJdbcContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package momosetkn.liquibase.kotlin.change.custom.jooq | ||
|
||
import momosetkn.liquibase.kotlin.change.custom.komapper.toJavaxSqlDataSource | ||
|
||
internal fun liquibase.database.Database.toJooqDSLContext(): org.jooq.DSLContext { | ||
val datasource = this.toJavaxSqlDataSource() | ||
val database = LiquibaseJooqConfig.provideDSLContext(datasource, this.shortName) | ||
return database | ||
} |
27 changes: 27 additions & 0 deletions
27
...ange/src/main/kotlin/momosetkn/liquibase/kotlin/change/custom/jooq/LiquibaseJooqConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package momosetkn.liquibase.kotlin.change.custom.jooq | ||
|
||
import org.jooq.SQLDialect | ||
import org.jooq.impl.DefaultDSLContext | ||
|
||
object LiquibaseJooqConfig { | ||
private val dialectMap = | ||
SQLDialect.entries.associateBy { it.name.lowercase() } + mapOf( | ||
"postgresql" to SQLDialect.POSTGRES, | ||
) | ||
|
||
var provideDSLContext: ( | ||
javaxSqlDataSource: javax.sql.DataSource, | ||
liquibaseDatabaseShortName: String | ||
) -> org.jooq.DSLContext = ::defaultProvideDSLContext | ||
|
||
fun defaultProvideDSLContext( | ||
javaxSqlDataSource: javax.sql.DataSource, | ||
liquibaseDatabaseShortName: String | ||
): org.jooq.DSLContext { | ||
return DefaultDSLContext(javaxSqlDataSource, getDialect(liquibaseDatabaseShortName)) | ||
} | ||
|
||
private fun getDialect(liquibaseDatabaseShortName: String): SQLDialect { | ||
return dialectMap[liquibaseDatabaseShortName] ?: SQLDialect.DEFAULT | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...main/kotlin/momosetkn/liquibase/kotlin/change/custom/jooq/RollbackTaskCustomJooqChange.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package momosetkn.liquibase.kotlin.change.custom.jooq | ||
|
||
import liquibase.change.custom.CustomChange | ||
import liquibase.change.custom.CustomTaskChange | ||
import liquibase.change.custom.CustomTaskRollback | ||
import liquibase.database.Database | ||
import liquibase.exception.ValidationErrors | ||
import liquibase.resource.ResourceAccessor | ||
|
||
class RollbackTaskCustomJooqChange( | ||
private val define: CustomRollbackableTaskChangeDefineImpl, | ||
) : CustomChange, CustomTaskChange, CustomTaskRollback { | ||
private var alreadyRollbackFlg = false | ||
private var resourceAccessor: ResourceAccessor? = null | ||
override fun getConfirmationMessage(): String { | ||
return define.confirmationMessage | ||
} | ||
|
||
override fun setUp() = Unit | ||
|
||
override fun setFileOpener(resourceAccessor: ResourceAccessor) { | ||
this.resourceAccessor = resourceAccessor | ||
} | ||
|
||
override fun validate(database: Database): ValidationErrors { | ||
return define.validateBlock(database.toJooqDSLContext()) | ||
} | ||
|
||
override fun execute(database: Database) { | ||
define.executeBlock(database.toJooqDSLContext()) | ||
} | ||
|
||
override fun rollback(database: Database) { | ||
// FIXME: CustomTaskRollback has a bug that causes it to be rolled back twice, but there is a workaround. | ||
// bugfix: https://github.com/liquibase/liquibase/pull/6266 | ||
if (!alreadyRollbackFlg) { | ||
define.rollbackBlock(database.toJooqDSLContext()) | ||
alreadyRollbackFlg = true | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...n/resources/META-INF/services/momosetkn.liquibase.kotlin.parser.KotlinScriptParserImports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
momosetkn.liquibase.kotlin.change.custom.jooq.CustomJooqChangeParserImports |
Oops, something went wrong.