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

Temporary fix for DropTable/CreateTable issue around temporal tables #35225

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

roji
Copy link
Member

@roji roji commented Nov 27, 2024

@maumar this is a bug in #32239, which I think is the result of a wider design issue in that PR; the trigger is simply having a DropTable followed by a CreateTable in the same migration. Your second processing loop for temporal tables (code) removes the temporal data from the table when it sees the DropTable, and when we get to the CreateTable we get an exception since there's no data at that point (code).

The hacky fix proposed here - which is probably OK for patching - is to simply not remove the data when we see DropTable, ensuring that it's still there when the CreateTable is processed. We've got two user reports on #35162; am waiting to hear how they got to having DropTable/CreateTable in the same migration in order to better understand how critical this bug is.

However, I think the design here is fundamentally problematic; you can't really do a pass over all operations (and then over the model for missing ones), storing the temporal data in a single dictionary; a single migration can create and drop the same table multiple times, each time with completely different temporal data. The current design flattens all that out, so that when you process e.g. the 1st CreateTable, you actually see the temporal data from the last CreateTable. IMHO the correct design here would be to have a single pass, extracting the temporal data when you see e.g. CreateTable, and remember it in the dictionary. If you have reach a table operation which doesn't contain temporal data, and don't have data in the dictionary (no e.g. CreateTable was present in the migration before), at that point you can consult the model, and again store the data in the dictionary. This way you always have the correct, up-to-date temporal data in the dictionary, as you're advancing in a single pass through all migration operations.

Fixes #35162

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.

Regression from EF Core 8 to 9: MigrationBuilder.DropTable Causes Issues with Subsequent Table Recreation
1 participant