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

c# ef-migrations entity-framework-core

Question

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
7
11/1/2017 5:24:12 AM

Accepted Answer

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.

8
11/1/2017 5:46:54 PM

Popular Answer

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.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow