-
Notifications
You must be signed in to change notification settings - Fork 695
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
chore! EXPOSED-655 Join column default fields defaultValueFun, defautValueInDb, isDatabaseGenerated into one field #2319
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -24,6 +24,20 @@ | |||||||||||||||||
-- Starting from version 0.57.0 | ||||||||||||||||||
INSERT INTO TEST DEFAULT VALUES | ||||||||||||||||||
``` | ||||||||||||||||||
|
||||||||||||||||||
* The fields `defaultValueFun`, `dbDefaultValue`, and `isDatabaseGenerated` have been consolidated into a single field, | ||||||||||||||||||
`default`, of type `ColumnDefault`. The previous setup with the three separate fields often led to inconsistencies | ||||||||||||||||||
and confusion regarding their various combinations. | ||||||||||||||||||
|
||||||||||||||||||
Here’s how you can migrate the common combinations: | ||||||||||||||||||
- `defaultValueFun != null && dbDefaultValue != null` (knows as `default()`) becomes `DatabaseColumnDefaultExpressionWithValue` | ||||||||||||||||||
- `dbDefaultValue != null` (knows as `defaultExpression()`) becomes `DatabaseColumnDefaultExpression` | ||||||||||||||||||
- `defaultValueFun != null` (knows as `clientDefault()`) becomes `ClientColumnDefaultValue` | ||||||||||||||||||
- `isDatabaseGenerated == true` (knows as `databaseGenerated`) becomes `DatabaseGeneratedColumnDefault` | ||||||||||||||||||
Comment on lines
+33
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean "known" instead of "knows" here?
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
If it is anticipated that a column will be transformed using `transform()`, | ||||||||||||||||||
the default value for that column should implement `TransformableColumnDefault`. However, not all defaults need to | ||||||||||||||||||
implement this interface; it is primarily necessary for columns with in-memory Kotlin values. | ||||||||||||||||||
|
||||||||||||||||||
## 0.56.0 | ||||||||||||||||||
* If the `distinct` parameter of `groupConcat()` is set to `true`, when using Oracle or SQL Server, this will now fail early with an | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,17 +28,10 @@ class Column<T>( | |
@Suppress("UNCHECKED_CAST") | ||
fun <S : T> referee(): Column<S>? = referee as? Column<S> | ||
|
||
/** Returns the function that calculates the default value for this column. */ | ||
var defaultValueFun: (() -> T)? = null | ||
internal var dbDefaultValue: Expression<T>? = null | ||
|
||
/** Returns the default value for this column on the database-side. */ | ||
fun defaultValueInDb() = dbDefaultValue | ||
|
||
internal var isDatabaseGenerated: Boolean = false | ||
|
||
/** Returns whether this column's value will be generated in the database. */ | ||
fun isDatabaseGenerated() = isDatabaseGenerated | ||
Comment on lines
-31
to
-41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it'd be great for users if we could try to go through the standard deprecation cycle where possible, using |
||
/** | ||
* The default value for this column. | ||
*/ | ||
var default: ColumnDefault<T>? = null | ||
|
||
internal var extraDefinitions = mutableListOf<Any>() | ||
|
||
|
@@ -121,12 +114,13 @@ class Column<T>( | |
else -> append(columnType.sqlType()) | ||
} | ||
|
||
val defaultValue = dbDefaultValue | ||
if (defaultValue != null) { | ||
val expressionSQL = currentDialect.dataTypeProvider.processForDefaultValue(defaultValue) | ||
if (!currentDialect.isAllowedAsColumnDefault(defaultValue)) { | ||
val defaultDatabaseValue = databaseDefaultExpression() | ||
|
||
if (defaultDatabaseValue != null) { | ||
val expressionSQL = currentDialect.dataTypeProvider.processForDefaultValue(defaultDatabaseValue) | ||
if (!currentDialect.isAllowedAsColumnDefault(defaultDatabaseValue)) { | ||
val clientDefault = when { | ||
defaultValueFun != null && dbDefaultValue == null -> " Expression will be evaluated on the client." | ||
hasClientDefault() -> " Expression will be evaluated on the client." | ||
!columnType.nullable -> " Column will be created with NULL marker." | ||
else -> "" | ||
} | ||
|
@@ -148,7 +142,7 @@ class Column<T>( | |
append(extraDefinitions.joinToString(separator = " ", prefix = " ") { "$it" }) | ||
} | ||
|
||
if (columnType.nullable || (defaultValue != null && defaultValueFun == null && !currentDialect.isAllowedAsColumnDefault(defaultValue))) { | ||
if (columnType.nullable || (defaultDatabaseValue != null && !currentDialect.isAllowedAsColumnDefault(defaultDatabaseValue))) { | ||
append(" NULL") | ||
} else if (!isPKColumn || (currentDialect is SQLiteDialect && !isSQLiteAutoIncColumn)) { | ||
append(" NOT NULL") | ||
|
@@ -163,14 +157,10 @@ class Column<T>( | |
val newColumn: Column<R> = Column(table, name, columnType) | ||
newColumn.foreignKey = foreignKey | ||
@Suppress("UNCHECKED_CAST") | ||
newColumn.dbDefaultValue = dbDefaultValue as Expression<R>? | ||
newColumn.isDatabaseGenerated = isDatabaseGenerated | ||
newColumn.default = default as ColumnDefault<R>? | ||
newColumn.extraDefinitions = extraDefinitions | ||
body?.let { newColumn.it() } | ||
|
||
if (defaultValueFun != null) { | ||
require(newColumn.defaultValueFun != null) { "defaultValueFun was lost on cloning the column" } | ||
} | ||
return newColumn | ||
} | ||
|
||
|
@@ -183,9 +173,7 @@ class Column<T>( | |
columnType = columnType | ||
).also { | ||
it.foreignKey = this.foreignKey | ||
it.defaultValueFun = this.defaultValueFun | ||
it.dbDefaultValue = this.dbDefaultValue | ||
it.isDatabaseGenerated = this.isDatabaseGenerated | ||
it.default = this.default | ||
it.extraDefinitions = this.extraDefinitions | ||
} | ||
|
||
|
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.
In my opinion, this document should only include information that is relevant to the user. It's good to justify the rationale behind our decisions, but 2 of these fields are actually internal and will mean nothing to most users.
For the list below, a user would never have used
dbDefaultValue != null
orisDatabaseGenerated == true
in their code, so I don't think they need to be noted.The breaking changes that should be mentioned are how:
Also, is there a migration element that is maybe missing?
What if for example the field
defaultValueFun
was being invoked somewhere in a user's logic like:Does there maybe need to something like
ColumnDefault.invoke()
that returns the result of invoking the Kotlin function if it exists or throws an error otherwise?