pekspro / EF-Migrations-Script-Generator-Task

24 stars 7 forks source link

[Question] What happens when a script fails halfway through? #1

Closed Poltergeisen closed 5 years ago

Poltergeisen commented 5 years ago

I've had trouble in the past running idempotent scripts because even though half of the scripts might work, if there is an error the migrations still get marked as ran. The issue with this is that if I try to re-run the script it won't fail anymore even if it should because it completely skips the failed migration.

pekspro commented 5 years ago

This repository is probably not the right place for questions like this, but it’s interesting so I’m trying to help anyway :-)

Do you have some example when this could happen? I have personally not experienced this. One thing to notice is that there are no transactions defined in the migrations script. I guess it’s up to the engine that executes the migrations to take care of that. I’m using the task Azure SQL Database Deployment to apply migrations. I’m not sure that if that task applies each migration in one transaction.

Poltergeisen commented 5 years ago

An example that I've recently come across is when you change a table's schema and then add an index. The schema change might be applied correctly, but the index could fail. In that case your initial script run would fail and mark the migration as completed.

I asked this on the Entity framework team's github and they said they'd look into it in the future. I just wanted to see if this library was fixing that issue or not.

You can close this issue if you'd like. Thank you!

Note: running dotnet ef database update actually does wrap each migration in their own transaction and run it separately so it doesn't have this issue.

https://github.com/aspnet/EntityFramework.Docs/issues/914

https://github.com/aspnet/EntityFrameworkCore/issues/7681

pekspro commented 5 years ago

Thanks for the info @adam-geisen . This was details I wasn’t aware of :-)