Skip to content

Commit

Permalink
Add regression tests for consistent scheme with default functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxr1998 committed May 3, 2023
1 parent 6e4e2fc commit 3b4ebf3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,23 @@ class DefaultsTest : DatabaseTestsBase() {
assertEquals(1, count)
}
}

@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)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@file:OptIn(ExperimentalTime::class)

package org.jetbrains.exposed.sql.kotlin.datetime

import kotlinx.datetime.*
Expand All @@ -24,6 +25,7 @@ import org.jetbrains.exposed.sql.vendors.OracleDialect
import org.jetbrains.exposed.sql.vendors.SQLServerDialect
import org.jetbrains.exposed.sql.vendors.h2Mode
import org.junit.Test
import org.junit.runners.model.MultipleFailureException
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
Expand Down Expand Up @@ -230,6 +232,7 @@ class DefaultsTest : DatabaseTestsBase() {
fun Expression<*>.itOrNull() = when {
currentDialectTest.isAllowedAsColumnDefault(this) ->
"DEFAULT ${currentDialectTest.dataTypeProvider.processForDefaultValue(this)} NOT NULL"

else -> "NULL"
}

Expand Down Expand Up @@ -352,9 +355,9 @@ class DefaultsTest : DatabaseTestsBase() {

withTables(foo) {
val d2020 = LocalDate(2020, 1, 1)
val dt2020 = d2020.atTime(0,0,0)
val dt2020m1w = d2020.minus(DateTimeUnit.WEEK).atTime(0,0,0)
val dt2020p1w = d2020.plus(DateTimeUnit.WEEK).atTime(0,0,0)
val dt2020 = d2020.atTime(0, 0, 0)
val dt2020m1w = d2020.minus(DateTimeUnit.WEEK).atTime(0, 0, 0)
val dt2020p1w = d2020.plus(DateTimeUnit.WEEK).atTime(0, 0, 0)

foo.insert { it[dt] = LocalDateTime(2019, 1, 1, 1, 1) }
foo.insert { it[dt] = dt2020 }
Expand All @@ -363,4 +366,23 @@ class DefaultsTest : DatabaseTestsBase() {
assertEquals(1, count)
}
}

@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)
}
}
}
}

0 comments on commit 3b4ebf3

Please sign in to comment.