Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: EXPOSED-99 SchemaUtils incorrectly compares datetime defaults #1802

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,19 @@ object SchemaUtils {
else -> processForDefaultValue(exp)
}
}
is Function<*> -> {
var processed = processForDefaultValue(exp)
if (
exp.columnType is IDateColumnType &&
(processed.startsWith("CURRENT_TIMESTAMP") || processed == "GETDATE()")
) {
when (currentDialect) {
is SQLServerDialect -> processed = "getdate"
is MariaDBDialect -> processed = processed.lowercase()
}
}
processed
}
else -> processForDefaultValue(exp)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.joda.time.DateTimeZone
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue

class JodaTimeDefaultsTest : JodaTimeBaseTest() {
object TableWithDBDefault : IntIdTable() {
Expand Down Expand Up @@ -214,7 +215,6 @@ class JodaTimeDefaultsTest : JodaTimeBaseTest() {

@Test
fun testDefaultExpressions01() {

fun abs(value: Int) = object : ExpressionWithColumnType<Int>() {
override fun toQueryBuilder(queryBuilder: QueryBuilder) = queryBuilder { append("ABS($value)") }

Expand Down Expand Up @@ -414,6 +414,25 @@ class JodaTimeDefaultsTest : JodaTimeBaseTest() {
}
}
}

@Test
fun testConsistentSchemeWithFunctionAsDefaultExpression() {
val foo = object : IntIdTable("foo") {
val name = text("name")
val defaultDateTime = datetime("defaultDateTime").defaultExpression(CurrentDateTime)
}

withDb {
try {
SchemaUtils.create(foo)

val actual = SchemaUtils.statementsRequiredToActualizeScheme(foo)
assertTrue(actual.isEmpty())
} finally {
SchemaUtils.drop(foo)
}
}
}
}

fun Table.insertAndWait(duration: Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ class DefaultsTest : DatabaseTestsBase() {

@Test
fun testDefaultExpressions01() {

fun abs(value: Int) = object : ExpressionWithColumnType<Int>() {
override fun toQueryBuilder(queryBuilder: QueryBuilder) = queryBuilder { append("ABS($value)") }

Expand Down