diff --git a/exposed-kotlin-datetime/api/exposed-kotlin-datetime.api b/exposed-kotlin-datetime/api/exposed-kotlin-datetime.api index 7294f5aced..a97c4641c1 100644 --- a/exposed-kotlin-datetime/api/exposed-kotlin-datetime.api +++ b/exposed-kotlin-datetime/api/exposed-kotlin-datetime.api @@ -122,6 +122,7 @@ public final class org/jetbrains/exposed/sql/kotlin/datetime/KotlinLocalDateColu public static final field Companion Lorg/jetbrains/exposed/sql/kotlin/datetime/KotlinLocalDateColumnType$Companion; public fun ()V public fun getHasTimePart ()Z + public fun nonNullValueAsDefaultString (Ljava/lang/Object;)Ljava/lang/String; public fun nonNullValueToString (Ljava/lang/Object;)Ljava/lang/String; public fun notNullValueToDB (Ljava/lang/Object;)Ljava/lang/Object; public fun sqlType ()Ljava/lang/String; diff --git a/exposed-kotlin-datetime/src/main/kotlin/org/jetbrains/exposed/sql/kotlin/datetime/KotlinDateColumnType.kt b/exposed-kotlin-datetime/src/main/kotlin/org/jetbrains/exposed/sql/kotlin/datetime/KotlinDateColumnType.kt index 561f6a45b2..5ab588ea89 100644 --- a/exposed-kotlin-datetime/src/main/kotlin/org/jetbrains/exposed/sql/kotlin/datetime/KotlinDateColumnType.kt +++ b/exposed-kotlin-datetime/src/main/kotlin/org/jetbrains/exposed/sql/kotlin/datetime/KotlinDateColumnType.kt @@ -139,6 +139,11 @@ class KotlinLocalDateColumnType : ColumnType(), IDateColumnType { else -> value } + override fun nonNullValueAsDefaultString(value: Any): String = when (currentDialect) { + is PostgreSQLDialect -> "${nonNullValueToString(value)}::date" + else -> super.nonNullValueAsDefaultString(value) + } + private fun longToLocalDate(instant: Long) = Instant.fromEpochMilliseconds(instant).toLocalDateTime(DEFAULT_TIME_ZONE).date companion object { diff --git a/exposed-kotlin-datetime/src/test/kotlin/org/jetbrains/exposed/sql/kotlin/datetime/DefaultsTest.kt b/exposed-kotlin-datetime/src/test/kotlin/org/jetbrains/exposed/sql/kotlin/datetime/DefaultsTest.kt index 469b953026..507567b538 100644 --- a/exposed-kotlin-datetime/src/test/kotlin/org/jetbrains/exposed/sql/kotlin/datetime/DefaultsTest.kt +++ b/exposed-kotlin-datetime/src/test/kotlin/org/jetbrains/exposed/sql/kotlin/datetime/DefaultsTest.kt @@ -501,6 +501,20 @@ class DefaultsTest : DatabaseTestsBase() { } } + @Test + fun testDateDefaultDoesNotTriggerAlterStatement() { + val date = LocalDate(2024, 2, 1) + + val tester = object : Table("tester") { + val dateWithDefault = date("dateWithDefault").default(date) + } + + withTables(tester) { + val statements = SchemaUtils.addMissingColumnsStatements(tester) + assertEquals(0, statements.size) + } + } + @Test fun testTimestampDefaultDoesNotTriggerAlterStatement() { val instant = Clock.System.now() // In UTC