[release/8.0] Fix to #32972 - The database default created by Migrations for primitive collections mapped to JSON is invalid #33048
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.
Port of #33039 and #33050
Fixes #32972
Description
Problem was that when adding new required column to an existing table we always need to provide default value (to fill the values for rows already in the table). For collection of primitives that get map to JSON we should be setting the value to empty JSON collection, i.e. '[]' but we were not doing that.
Customer impact
Incorrect migration generated when new primitive collection property is added to an existing table. Workaround is to manually edit the migration code. This is painful because primitive collections is highly anticipated feature in EF8, and when customers want to incorporate it into their existing projects they get hit by this bug.
How found
Customer reported on 8.
Regression
No, primitive collections are a new feature in 8.
Testing
Multiple tests added.
Risk
Low. Change is straightforward (adding proper hard-coded default value representing empty JSON collection) and we already do something similar for entities mapped to JSON. Added quirk just to be safe.