Skip to content

Commit

Permalink
Merge pull request #40 from momosetkn/feat/remopve_reduncant_dsl
Browse files Browse the repository at this point in the history
Remove clazz, className property
  • Loading branch information
momosetkn authored Sep 24, 2024
2 parents 4d6d807 + 5742224 commit bb08fe5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
40 changes: 23 additions & 17 deletions dsl/src/main/kotlin/momosetkn/liquibase/kotlin/dsl/ChangeSetDsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1322,26 +1322,19 @@ class ChangeSetDsl(

/**
* Applies a custom-change to the change set.
* This function requires at least one of the parameters `class`, `clazz`, or `className`.
* Class is requiring implements the [liquibase.change.custom.CustomChange]
* [official-document](https://docs.liquibase.com/change-types/custom-change.html)
*
* @param `class` specify KClass or Class<*> of CustomChange or className of CustomChange.
* @param clazz specify KClass or Class<*> of CustomChange or className of CustomChange. not official param.
* @param className className of CustomChange. not official param.
* @param block Key-value to be given to CustomChange.
*/
fun customChange(
@Suppress("FunctionParameterNaming")
`class`: Any? = null,
clazz: Any? = null,
className: String? = null,
`class`: Any,
block: (KeyValueDsl.() -> Unit)? = null,
) {
val overrideClassName = (`class` ?: clazz ?: className)
?: error("Should specify either 'class' or 'clazz' or 'className' property for 'customChange'")
val change = changeSetSupport.createChange("customChange") as CustomChangeWrapper
change.setClass(overrideClassName.evalClassNameExpressions(changeLog))
change.setClass(`class`.evalClassNameExpressions(changeLog))
block?.let {
val dsl = KeyValueDsl(changeLog)
val map = wrapChangeLogParseException { dsl(block) }
Expand Down Expand Up @@ -1415,6 +1408,16 @@ class ChangeSetDsl(
changeSetSupport.addChange(change)
}

/**
* Executes a raw SQL change.
* [official-document](https://docs.liquibase.com/change-types/sql.html)
*
* @param dbms The type of database. [database-type](https://docs.liquibase.com/start/tutorials/home.html)
* @param endDelimiter The delimiter for the end of the SQL statement. Default is ";".
* @param splitStatements Whether to split the SQL statements. Default is true.
* @param stripComments Whether to strip comments from the SQL. Default is true.
* @param block The DSL-block that returns SQL strings
*/
fun sql(
dbms: String? = null,
endDelimiter: String? = null,
Expand Down Expand Up @@ -1453,14 +1456,17 @@ class ChangeSetDsl(
stripComments: Boolean? = null,
comment: String? = null,
) {
val change = changeSetSupport.createChange("sql") as RawSQLChange
change.dbms = dbms
change.endDelimiter = endDelimiter
change.isSplitStatements = splitStatements
change.isStripComments = stripComments
change.sql = sql.evalExpressions(changeLog)
change.comment = comment?.evalExpressions(changeLog)
changeSetSupport.addChange(change)
sql(
dbms = dbms,
endDelimiter = endDelimiter,
splitStatements = splitStatements,
stripComments = stripComments,
) {
if (comment != null) {
comment(comment)
}
sql
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,28 +240,21 @@ class PreConditionDsl<PRECONDITION_LOGIC : PreconditionLogic>(

/**
* Applies a custom-precondition to the preconditions.
* This function requires at least one of the parameters `class`, `clazz`, or `className`.
* Class is requiring implements the [liquibase.precondition.CustomPrecondition]
* [official-document](https://docs.liquibase.com/concepts/changelogs/preconditions.html)
*
* @param `class` specify KClass or Class<*> of CustomChange or className of CustomChange.
* @param clazz specify KClass or Class<*> of CustomChange or className of CustomChange. not official param.
* @param className className of CustomChange. not official param.
* @param block Key-value to be given to CustomChange.
*/
fun customPrecondition(
@Suppress("FunctionParameterNaming")
`class`: Any? = null,
clazz: Any? = null,
className: String? = null,
`class`: Any,
block: KeyValueDsl.() -> Unit,
) {
val precondition = CustomPreconditionWrapper()

@Suppress("MaxLineLength")
val overrideClassName = (`class` ?: clazz ?: className)
?: error("Should specify either 'class' or 'clazz' or 'className' property for 'customPrecondition' preConditions")
precondition.className = overrideClassName.evalClassNameExpressions(changeLog)
precondition.className = `class`.evalClassNameExpressions(changeLog)
val dsl = KeyValueDsl(changeLog)
val map = dsl(block)
map.forEach { (key, value) ->
Expand Down

0 comments on commit bb08fe5

Please sign in to comment.