Skip to content

Commit b306dd7

Browse files
committed
Refactor timestamp handling in AuditableLongIdTable to use OffsetDateTime and CurrentOffsetDateTime
1 parent 9fbebea commit b306dd7

7 files changed

Lines changed: 28 additions & 27 deletions

File tree

api/surf-database-r2dbc.api

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,21 @@ public final class dev/slne/surf/database/columns/NativeUuidColumnTypeKt {
6363
}
6464

6565
public final class dev/slne/surf/database/columns/time/CurrentOffsetDateTime : dev/slne/surf/database/columns/time/CurrentTimestampBase {
66-
public static final field INSTANCE Ldev/slne/surf/database/columns/time/CurrentOffsetDateTime;
66+
public fun <init> ()V
67+
public fun <init> (Z)V
68+
public synthetic fun <init> (ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
6769
}
6870

6971
public class dev/slne/surf/database/columns/time/CurrentTimestampBase : org/jetbrains/exposed/v1/core/Function {
70-
public fun <init> (Lorg/jetbrains/exposed/v1/core/IColumnType;)V
72+
public fun <init> (Lorg/jetbrains/exposed/v1/core/IColumnType;Z)V
73+
public synthetic fun <init> (Lorg/jetbrains/exposed/v1/core/IColumnType;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
7174
public fun toQueryBuilder (Lorg/jetbrains/exposed/v1/core/QueryBuilder;)V
7275
}
7376

7477
public final class dev/slne/surf/database/columns/time/CurrentZonedDateTime : dev/slne/surf/database/columns/time/CurrentTimestampBase {
75-
public static final field INSTANCE Ldev/slne/surf/database/columns/time/CurrentZonedDateTime;
78+
public fun <init> ()V
79+
public fun <init> (Z)V
80+
public synthetic fun <init> (ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
7681
}
7782

7883
public final class dev/slne/surf/database/columns/time/OffsetDateTimeColumnType : dev/slne/surf/database/columns/time/UtcInstantDateTimeColumnType {

build.gradle.kts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,4 @@ publishing {
6464
repositories {
6565
slneReleases()
6666
}
67-
}
68-
69-
afterEvaluate {
70-
tasks.named("publishPluginMavenPublicationToMaven-releasesRepository") {
71-
enabled = false
72-
}
73-
tasks.named("publishPluginMavenPublicationToMavenLocal") {
74-
enabled = false
75-
}
7667
}

gradle.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ kotlin.stdlib.default.dependency=false
33
org.gradle.parallel=true
44
#org.gradle.caching=true
55
#org.gradle.configureondemand=true
6-
7-
version=1.0.1-SNAPSHOT
6+
version=1.1.0-SNAPSHOT

src/main/kotlin/dev/slne/surf/database/columns/time/OffsetDateTimeColumnType.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ class OffsetDateTimeColumnType :
2323
fun Table.offsetDateTime(name: String): Column<OffsetDateTime> =
2424
registerColumn(name, OffsetDateTimeColumnType())
2525

26-
object CurrentOffsetDateTime :
27-
CurrentTimestampBase<OffsetDateTime>(OffsetDateTimeColumnType.INSTANCE)
26+
class CurrentOffsetDateTime(includeUpdate: Boolean = false) :
27+
CurrentTimestampBase<OffsetDateTime>(OffsetDateTimeColumnType.INSTANCE, includeUpdate)

src/main/kotlin/dev/slne/surf/database/columns/time/UtcInstantDateTimeColumnType.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,16 @@ abstract class UtcInstantDateTimeColumnType<T : Any> :
162162
}
163163
}
164164

165-
open class CurrentTimestampBase<T>(columnType: IColumnType<T & Any>) : Function<T>(columnType) {
165+
open class CurrentTimestampBase<T>(
166+
columnType: IColumnType<T & Any>,
167+
private val includeUpdate: Boolean = false
168+
) : Function<T>(columnType) {
166169
override fun toQueryBuilder(queryBuilder: QueryBuilder) = queryBuilder {
167170
+when {
168-
(currentDialect as? MysqlDialect)?.isFractionDateTimeSupported() == true -> "CURRENT_TIMESTAMP(6)"
169-
else -> "CURRENT_TIMESTAMP"
171+
(currentDialect as? MysqlDialect)?.isFractionDateTimeSupported() == true -> "CURRENT_TIMESTAMP(6) ${
172+
if (includeUpdate) "ON UPDATE CURRENT_TIMESTAMP(6)" else ""
173+
}"
174+
else -> "CURRENT_TIMESTAMP ${if (includeUpdate) "ON UPDATE CURRENT_TIMESTAMP" else ""}"
170175
}
171176
}
172177
}

src/main/kotlin/dev/slne/surf/database/columns/time/ZonedDateTimeColumnType.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dev.slne.surf.database.columns.time
33
import org.jetbrains.exposed.v1.core.Column
44
import org.jetbrains.exposed.v1.core.Table
55
import java.time.Instant
6+
import java.time.OffsetDateTime
67
import java.time.ZoneId
78
import java.time.ZonedDateTime
89

@@ -23,5 +24,5 @@ class ZonedDateTimeColumnType :
2324
fun Table.zonedDateTime(name: String): Column<ZonedDateTime> =
2425
registerColumn(name, ZonedDateTimeColumnType())
2526

26-
object CurrentZonedDateTime :
27-
CurrentTimestampBase<ZonedDateTime>(ZonedDateTimeColumnType.INSTANCE)
27+
class CurrentZonedDateTime(includeUpdate: Boolean = false):
28+
CurrentTimestampBase<ZonedDateTime>(ZonedDateTimeColumnType.INSTANCE, includeUpdate)
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package dev.slne.surf.database.table
22

3+
import dev.slne.surf.database.columns.time.CurrentOffsetDateTime
4+
import dev.slne.surf.database.columns.time.offsetDateTime
35
import org.jetbrains.exposed.v1.core.dao.id.ULongIdTable
4-
import org.jetbrains.exposed.v1.javatime.CurrentTimestamp
5-
import org.jetbrains.exposed.v1.javatime.timestamp
66

77
open class AuditableLongIdTable(name: String = "") : ULongIdTable(name) {
8-
val createdAt = timestamp("created_at")
9-
.defaultExpression(CurrentTimestamp)
10-
val updatedAt = timestamp("updated_at")
11-
.defaultExpression(CurrentTimestamp)
8+
val createdAt = offsetDateTime("created_at")
9+
.defaultExpression(CurrentOffsetDateTime())
10+
val updatedAt = offsetDateTime("updated_at")
11+
.defaultExpression(CurrentOffsetDateTime(true))
1212
}
1313

0 commit comments

Comments
 (0)