Fix columnType.Unique() returns true for non-unique index DDL. #154
+19
−1
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.
What did this pull request do?
Fixes an issue where the migrator determines that a column is unique (true) when referenced in an index DDL without further determining whether the index is unique. As a result, a model with a non-unique index tag is always be deemed different than the DDL which always triggers a table migration. The fix is to determine the column uniqueness based on whether the referencing index DDL is
CREATE UNIQUE INDEX ...
and notCREATE INDEX
.Set the
ColumnType.UniqueValue
based on the column being referenced in a UNIQUE index (not just any index).User Case Description
Common use case of to add a non unique index on a foreign key to support cascade delete. As a result, the auto-migrate detecting a difference and ALWAYS is migrating the table.
The use case: model defined as Person with
1-*
relation to Parent (so the index cannot be unique).Results in:
ColumnType.UniqueValue
=true
.