-
Notifications
You must be signed in to change notification settings - Fork 707
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
feat: EXPOSED-733 Detect column type change for migrations in H2 #2419
Open
joc-a
wants to merge
1
commit into
main
Choose a base branch
from
joc/exposed-733-H2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -365,6 +365,9 @@ object SchemaUtils { | |
} else { | ||
columnType.nullable | ||
} | ||
|
||
val incorrectType = if (currentDialect.supportsColumnTypeChange) isIncorrectType(existingCol, col) else false | ||
|
||
val incorrectNullability = existingCol.nullable != colNullable | ||
|
||
val incorrectAutoInc = isIncorrectAutoInc(existingCol, col) | ||
|
@@ -373,9 +376,9 @@ object SchemaUtils { | |
|
||
val incorrectCaseSensitiveName = existingCol.name.inProperCase() != col.nameUnquoted().inProperCase() | ||
|
||
val incorrectSizeOrScale = isIncorrectSizeOrScale(existingCol, columnType) | ||
val incorrectSizeOrScale = if (incorrectType) false else isIncorrectSizeOrScale(existingCol, columnType) | ||
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. The size and scale are only compared if the types are confirmed to be equivalent because the size and scale differences are taken into account when comparing the types. This might change later as we refine this feature. |
||
|
||
ColumnDiff(incorrectNullability, incorrectAutoInc, incorrectDefaults, incorrectCaseSensitiveName, incorrectSizeOrScale) | ||
ColumnDiff(incorrectNullability, incorrectType, incorrectAutoInc, incorrectDefaults, incorrectCaseSensitiveName, incorrectSizeOrScale) | ||
}.filterValues { it.hasDifferences() } | ||
|
||
redoColumns.flatMapTo(statements) { (col, changedState) -> col.modifyStatements(changedState) } | ||
|
@@ -398,6 +401,10 @@ object SchemaUtils { | |
return statements | ||
} | ||
|
||
private fun isIncorrectType(columnMetadata: ColumnMetadata, column: Column<*>): Boolean { | ||
return !currentDialect.areEquivalentColumnTypes(columnMetadata.sqlType, columnMetadata.jdbcType, column.columnType.sqlType()) | ||
} | ||
|
||
private fun isIncorrectAutoInc(columnMetadata: ColumnMetadata, column: Column<*>): Boolean = when { | ||
!columnMetadata.autoIncrement && column.columnType.isAutoInc && column.autoIncColumnType?.sequence == null -> | ||
true | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
should we store old and new types directly?
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.
I'm not sure why that's necessary. Could you please elaborate?
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.
The
ColumnDiff
class represents the difference between definition and metadata. It would be useful to have both types hereThere 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.
The
ColumnDiff
class, as it is now, represents whether there is a difference between the Exposed definition and the metadata. It answers a yes or no question. All the properties in the class are of type Boolean. The way it works is that we check if any of the properties are true, and in that case themodifyColumn
statement is invoked, which contains the ALTER statement that modifies the column to have the required type if needed. If I add both types to this class, they would actually not be used anywhere, because the comparison between the two types is already done a step before we create an instance of this class. This class is simply a result of that comparison. This is the approach we currently have for all the differences that we currently detect for columns (nullability, defaults, auto-increment, etc.). Please let me know if you had envisioned an entirely different approach to the one we currently have.