实体框架核心:如果我们永远不会还原迁移,删除Migration.Designer.cs是否安全? [英] Entity Framework Core: Is it safe to delete Migration.Designer.cs if we will never Revert a migration?
问题描述
我们有一个包含约200个表的数据库架构。
为每次迁移创建的模型快照(Migration.Designer.cs)约为2万行。因此,进行大量迁移确实会减慢我们在CI上的构建速度(使用〜30个迁移构建解决方案需要6分钟(如果不进行迁移,则需要4分钟)。
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?
推荐答案
模型快照是否用于任何其他用途?
Are model snapshots used for anything else except Revert-Migration?
是的。在一些需要的情况下。在SQL Server上,这些情况是:
Yes. There are a few edge cases where it's needed. On SQL Server, those cases are:
- 当列变窄或计算表达式更改并且索引需要重建时,AlterColumn
- 在索引唯一且引用可为空的列时在内存优化表上创建索引
在大多数情况下,删除它可能是安全的,但是请在执行此操作后测试您的迁移是否仍然有效。
So most of the time it's probably safe to delete, but please test that your migrations still work after doing so.
这篇关于实体框架核心:如果我们永远不会还原迁移,删除Migration.Designer.cs是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!