Fix to #27844 - EF Core 6.0 temporal table migration when altering computed column not generating correct script #32398
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.
Working with computed column on a temporal table requires special processing - we need to disable the versioning, add the computed column to regular table and a column with the same name/type/position to the history table, but as a regular column. After all is done we re-enable versioning. Historical information on the computed column will be copied to the counterpart column in history table without issue.
One thing that we can't do is modifying computed column SQL when table is temporal. What happens in case of CCSQL modification, we drop the column and create a new one with new CCSQL. This is not an issue for regular table, because the value is computed anyway, so old value is useless. But when we drop-create column, that column gets created at the last position in the table, and so the table no longer matches it's history table exactly (positions of columns may differ). We would have to drop+recreate column on a history table, but that results in losing historical data of that column. And that is valuable data, unlike for regular table. We could enable that scenario once/if we support table rebuilds.
Fixes #27844