Entity Framework Core: Is it safe to delete Migration.Designer.cs if we will never Revert a migration?

此生再无相见时 提交于 2019-12-09 11:05:44

问题


We have a database schema with ~200 tables. Model snapshot (Migration.Designer.cs) which is created for each migration is ~20K lines. So, having quite a number of migrations really slows down our build on CI (with ~30 migrations building a solution takes 6 minutes with migrations or 4 minutes without them).

So, to the question: is it safe to delete model snapshots for old migrations (that we know we will never Revert)? Are model snapshots used for anything else except Revert-Migration?


回答1:


Are model snapshots used for anything else except Revert-Migration?

Yes. There are a few edge cases where it's needed. On SQL Server, those cases are:

  • AlterColumn when the column is narrowed or the computed expression is changed and the indexes need to be rebuilt
  • CreateIndex on a memory-optimized table when the index is unique and references nullable columns

So most of the time it's probably safe to delete, but please test that your migrations still work after doing so.




回答2:


Got the same problem on my current project. Above 400 migraitons and 6m lines of code inside .Designer. Here is how I managed to resolve this problem:

MigrationProject.csproj

  <PropertyGroup>
     ...
     <DefaultItemExcludes Condition="'$(Configuration)' == 'Debug' ">$(DefaultItemExcludes);Migrations\**\*.Designer.cs</DefaultItemExcludes>
  </PropertyGroup>

This way you dont need to reset migration neither delete .Designer files.



来源:https://stackoverflow.com/questions/47048721/entity-framework-core-is-it-safe-to-delete-migration-designer-cs-if-we-will-nev

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!