-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Script-Migration command should begin/commit transactions #7681
Comments
Did you use the
command swith? https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell |
Yes, However, the row with MigrationId = '20170217083056_EFSomeTableInitialCreate' is added at the end of the script. If an error occurs on script deployment before the row is inserted, you cannot redeploy the script since the table __EFMigrationsHistory does not contains migration row. |
When we execute migrations from tools/code, we use transactions for most operations (though there are some DDL operations that can't be executed in a transaction). @bricelam should we be emitting |
@rowanmiller I think it depends on whether most tools (e.g. MSDeploy, SSMS, SSDT, etc.) give you the option to run it inside a transaction... |
We discussed this at length and have decided that at this time we will not start generating any transactions code in the script. We want to leave the scripts generated to be useful in a variety of scenarios, some of which don't involve use of transactions, and some of which will do transactions themselves separately from the script. We considered emitting a comment saying this at the start of the script, but for now we don't think there is enough value in doing that. We will re-consider this if there is more feedback and/or specific pit-of-failure scenarios that we see people falling into. |
Based on feedback, we're re-considering whether the script should include the BEGIN TRANSACTION and COMMIT statements corresponding to where transactions occur during Update-Database. |
Hi Brice, I see this is attached to milestone 3.0.0. Will this definitely make it into EF Core 3.0? Thanks, Jon |
@jonsagara Our 3.0 planning happend before I took on porting EF6 to .NET Core. I need to do another pass of punting my 3.0 issues. That said, I still hope I can get to this one during the 3.0 milestone. |
I recently discovered that this is important for |
@esquino I honestly don't understand why, but it looks like evaluating DECLARE @XACT_STATE SMALLINT = XACT_STATE();
IF @XACT_STATE = 1 AND NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20200409230613_Second')
BEGIN
-- Migrate Data
END; |
I looked into MSDeploy (used by Web Publish) and it's safe to include the BEGIN/COMMIT statements in the script. I was worried we might run into nested transaction errors because it automatically wraps the entire script inside a transaction, but it simply ignores the statements. I filed dotnet/sdk#12676 to, once this is implemented, disable the automatic transaction and start using the script's transactions instead. |
Design meeting notes:
|
Any update on this? |
@woeterman94 Will be available in 5.0.0-rc.1 |
@bricelam I have an issue with this. I opened a feature request issue about it here. |
Script-Migration command currently generate creation (or drop) script without checking objects existence.
If an error happens during script deployment (network, server error, ...), you can't redeploy generated script.
A check is done for table __EFMigrationsHistory :
It should be the same for user tables, ex of generated creation script :
The modification should be done in creation script (check if not exists) and drop script (check if exists).
The text was updated successfully, but these errors were encountered: