-
Notifications
You must be signed in to change notification settings - Fork 674
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
Add support for MySQL 'ON UPDATE CURRENT_TIMESTAMP' default expression #986
Conversation
Please note that this syntax is not support with h2 even in MySQL mode. A real MySQL/MariaDB is needed for testing. |
@xJoeWoo , as I can see from MySQL documentation I would prefer some kind of extention on
BTW, MySQL 8.0.13+ has normal support for expressions in DEFAULT! |
@@ -117,14 +122,26 @@ open class MysqlDialect : VendorDialect(dialectName, MysqlDataTypeProvider, Mysq | |||
TransactionManager.current().db.isVersionCovers(BigDecimal("8.0")) | |||
} | |||
|
|||
abstract class OnUpdateCurrentTimestamp<T>(private val currentTimestamp: Expression<T>) : Expression<T>() { | |||
|
|||
fun ddlDefault():String = QueryBuilder(false).apply { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not to make it in toQueryBuilder
function?
/** | ||
* Expression of MySQL syntax `DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP` | ||
*/ | ||
class CurrentTimestampOnUpdateCurrentTimestamp<T : Temporal> : MysqlDialect.OnUpdateCurrentTimestamp<T>(CurrentTimestamp<T>()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide similar for exposed-jodatime
module.
According to this pull, it is supported in all modes with h2 now |
Support for this expression will be available in upcoming version 0.52.0 via PR #2125 object : Table("tester") {
val created = timestamp("created")
.defaultExpression(CurrentTimestamp)
.withDefinition("ON UPDATE", CurrentTimestamp)
}
// generates SQL:
// CREATE TABLE IF NOT EXISTS tester (created DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) NOT NULL) |
Adds support for MySQL
column DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
syntax.This default statement is useful when other app updated the row, but without/forget assigning the "update time" column.
Test statements output
MySQL 5.5:
MySQL 8.0: