Skip to content
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

[6.0] Fix to #26166 - Idempotent migration script generates problematic temporal table alter statement #26193

Merged
merged 1 commit into from
Sep 30, 2021

Conversation

maumar
Copy link
Contributor

@maumar maumar commented Sep 28, 2021

Problem was that for idempotent migration scripts that convert non-temporal table to temporal we need to wrap the period switching statement in exec. Otherwise sql parser(?) complains that the command is invalid because period already exists. This is a false negative - the statement will not actually execute if this migration has already been applied. Exec fixes the problem since the statement inside it can't be parsed. This is how we deal with similar issues in other places in the code.

Fixes #26166

@maumar maumar changed the title Fix to #26166 - Idempotent migration script generates problematic temporal table alter statement [6.0] Fix to #26166 - Idempotent migration script generates problematic temporal table alter statement Sep 28, 2021
@maumar
Copy link
Contributor Author

maumar commented Sep 28, 2021

@Pilchie for approval - low risk fix (adding exec around a sql statement) in a new feature (temporal tables). issue has recently been found by a customer

@maumar maumar requested review from a team and bricelam September 28, 2021 03:59
.Append(")")
.ToString();

if (options.HasFlag(MigrationsSqlGenerationOptions.Idempotent))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested disable period, as well as enable/disable versioning - they all work. Only enable period causes issues it seems

@Pilchie
Copy link
Member

Pilchie commented Sep 29, 2021

Scenario approved for EFCore 6.0, pending code review sign-off.

…poral table alter statement

Problem was that for idempotent migration scripts that convert non-temporal table to temporal we need to wrap the period switching statement in exec. Otherwise sql parser(?) complains that the command is invalid because period already exists. This is a false negative - the statement will not actually execute if this migration has already been applied. Exec fixes the problem since the statement inside it can't be parsed. This is how we deal with similar issues in other places in the code.

Fixes #26166
@maumar maumar merged commit d5a02d7 into release/6.0 Sep 30, 2021
@maumar maumar deleted the fix26166 branch September 30, 2021 02:06
Copy link
Contributor

@bricelam bricelam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Idempotent migration script generates problematic temporal table alter statement
4 participants