-
Notifications
You must be signed in to change notification settings - Fork 686
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-283 Date/Time defaults falsely trigger ALTER statements #1981
Conversation
94c99bc
to
82e85ad
Compare
313b282
to
e11494f
Compare
65fe85b
to
1895002
Compare
@joc-a @e5l A though about The new functions create strings that match the metadata exactly and the only place
This means all generated SQL with defaults is going to now be different when logged, which works fine. So maybe it would be worth assessing if it would be possible to use this new logic directly inside of the original functions instead. Or at least directly inside the issue source, at class LiteralOp<T>(
override val columnType: IColumnType,
val value: T
) : ExpressionWithColumnType<T>() {
override fun toQueryBuilder(queryBuilder: QueryBuilder): Unit = queryBuilder {
// +columnType.valueToString(value)
+columnType.valueAsDefaultString(value)
}
} I guess my overall thought is: Could The majority of column types will definitely need to override val incorrectDefaults = existingCol.defaultDbValue != col.dbDefaultValue?.let {
columnType.nonNullValueAsDefaultString(it)
} |
@joc-a, please check CI |
1895002
to
a6e03fa
Compare
@bog-walk My initial approach was to change the |
…tement -The default value, compared to the one from the metadata, used to be wrapped in single quotes, so there's a check to remove them now in `DataTypeProvider.dbDefaultToString` function. -In the `sanitizedDefault` function in `JdbcDatabaseMetadataImpl`, the default value String obtained fromm the metadata for Oracle and H2_Oracle is now trimmed of its single quotes only when a single quote exists at the start AND end. -In `ColumnType`, two new functions were added to deal with the String representation of a column's default value to match the default value obtained from the metadata (eg: `'2024-01-31 16:50:27.222'::timestamp without time zone` for PostgreSQL): `valueAsDefaultString` and `nonNullValueAsDefaultString`. -In the `processForDefaultValue` function in `PostgreSQLDataTypeProvider`, `valueAsDefaultString` is now used when the type of the expression is LiteralOp. -`KotlinInstantColumnType` and `JavaInstantColumnType` now override `nonNullValueAsDefaultString` to match the default value obtained from the metadata for PostgreSQL and H2 Oracle. -Breaking change: In `nonNullValueToString` for `KotlinInstantColumnType` and `JavaDateColumnType`, the formatted String for MySQL did not match the format received from the metadata when `isFractionDateTimeSupported` is true, so a new formatter specific to that is now used. -Fix failing tests in `ArrayColumnTypeTests` by overriding `nonNullValueToString` in `ArrayColumnType` and moving the logic for handling a non-null value from the overridden `valueToString` to `nonNullValueToString`.
…ement -`KotlinLocalDateTimeColumnType`, `JavaLocalDateTimeColumnType`, and `DateColumnType` now override `nonNullValueAsDefaultString` to match the default value obtained from the metadata for PostgreSQL and H2 Oracle. -Breaking change: In `nonNullValueToString` for `KotlinLocalDateTimeColumnType`, the formatted String for MySQL did not match the format received from the metadata when `isFractionDateTimeSupported` is true, so a new formatter specific to MySQL is now used.
-`KotlinLocalDateColumnType` and `JavaLocalDateColumnType` now override `nonNullValueAsDefaultString` to match the default value obtained from the metadata for PostgreSQL. -In `DateColumnType`, `nonNullValueAsDefaultString` is modified to match the default value obtained from the metadata for PostgreSQL.
-`KotlinLocalTimeColumnType` and `JavaLocalTimeColumnType` now override `nonNullValueAsDefaultString` to match the default value obtained from the metadata for PostgreSQL and MySQL. The formatted String for MySQL (with fractional seconds) did not match the format received from the metadata (without fractional seconds), so a new formatter for MySQL is used which discards the fractional seconds.
…gers ALTER statement -`KotlinOffsetDateTimeColumnType`, `JavaOffsetDateTimeColumnType`, and `DateTimeWithTimeZoneColumnType` now override `nonNullValueAsDefaultString` to match the default value obtained from the metadata for PostgreSQL, MySQL, and H2 Oracle.
a6e03fa
to
902dbb9
Compare
Date/Time column type defaults false trigger ALTER statements because of a mismatch when comparing the default value obtained from the metadata (which Exposed sanitizes) with the formatted default value of the column type. The following are the mismatches that were fixed in this PR.
Mismatches for timestamp column type:
Default value from metadata:
'2024-02-07 12:42:26.251'::timestamp without time zone
Default value formatted by Exposed:
'2024-02-07T12:42:26.251'
Default value from metadata:
TIMESTAMP '2024-02-07 12:42:27.453
Default value formatted by Exposed:
TIMESTAMP '2024-02-07 12:42:27.453'
Default value from metadata:
2024-02-07T12:42:25.31
Default value formatted by Exposed:
'2024-02-07T12:42:25.31'
Default value from metadata:
2024-02-07 12:42:24.508000
Default value formatted by Exposed:
'2024-02-07T12:42:24.508'
Default value from metadata:
2024-02-07T12:42:23.494
Default value formatted by Exposed:
'2024-02-07T12:42:23.494'
Mismatches for timestampWithTimeZone column type:
Default value from metadata:
'2024-02-07 14:55:28.1+00'::timestamp with time zone
Default value formatted by Exposed:
'2024-02-07T23:55:28.100+09:00'
Default value from metadata:
TIMESTAMP '2024-02-07 23:55:29.776000 +09:00
Default value formatted by Exposed:
TIMESTAMP '2024-02-07 23:55:29.776000 +09:00'
Default value from metadata:
TIMESTAMP '2024-02-07 14:55:24.9
Default value formatted by Exposed:
TIMESTAMP '2024-02-07T23:55:24.900+09:00'
Default value from metadata:
2024-02-07T23:55:26.812+09:00
Default value formatted by Exposed:
'2024-02-07T23:55:26.812+09:00'
Default value from metadata:
2024-02-07 14:55:25.749000
Default value formatted by Exposed:
'2024-02-07 23:55:25.749000+09:00'
Mismatches for datetime column type:
Default value from metadata:
'2024-02-08 00:02:34.935'::timestamp without time zone
Default value formatted by Exposed:
'2024-02-08T00:02:34.935'
Default value from metadata:
TIMESTAMP '2024-02-08 00:02:36.459
Default value formatted by Exposed:
TIMESTAMP '2024-02-08 00:02:36.459'
Default value from metadata:
2024-02-08 00:02:45.394000
Default value formatted by Exposed:
'2024-02-08T00:02:45.394'
Default value from metadata:
2024-02-08T00:02:33.662
Default value formatted by Exposed:
'2024-02-08T00:02:33.662'
Mismatches for date column type:
Default value from metadata:
'2024-02-01'::date
Default value formatted by Exposed:
'2024-02-01'
Default value from metadata:
DATE '2024-02-01
Default value formatted by Exposed:
DATE '2024-02-01'
Default value from metadata:
2024-02-01
Default value formatted by Exposed:
'2024-02-01'
Default value from metadata:
2024-02-01
Default value formatted by Exposed:
'2024-02-01'
Mismatches for time column type:
Default value from metadata:
'00:11:17.34'::time without time zone
Default value formatted by Exposed:
'00:11:17.34'
Default value from metadata:
TIMESTAMP '1900-01-01 00:11:12
Default value formatted by Exposed:
TIMESTAMP '1900-01-01 00:11:12'
Default value from metadata:
00:11:16.088
Default value formatted by Exposed:
'00:11:16.088'
Default value from metadata:
00:11:13
Default value formatted by Exposed:
'00:11:13.431'