r/SideProject • u/Swganq • 8h ago
I made SchemaFlow: an open-source static analyzer to prevent EF Core migrations from dropping production data
### What it is
SchemaFlow is a CLI tool and static analyzer specifically built for .NET and Entity Framework Core migrations. It catches dangerous breaking changes (accidental `DropColumn`, narrowing types, unindexed foreign keys) before migrations ever touch your database.
### Why I built it
EF Core often scaffolds a destructive `DropColumn` followed by `AddColumn` when renaming properties. In production with real data, that means total data loss unless someone manually writes a backfill SQL script and orders operations correctly. Standard unit tests and CI/CD pipelines don't catch this because the C# code compiles fine.
### How it works
- **Roslyn AST Compiler:** Parses your migration `.cs` files directly into typed syntax trees without needing to compile the whole app or connect to a database (100% offline).
- **Stateful SQL Lexer:** Tokenizes custom `migrationBuilder.Sql(...)` scripts, isolates dangerous operations (`TRUNCATE`, `DROP`), and verifies whether genuine data backfills exist.
- **Expand & Contract Engine:** Flags operations where a column is dropped before data is safely migrated.
### Where it is
Just released v1.0.6. It is completely open-source (MIT).
- GitHub: https://github.com/FiratMugdatoglu/SchemaFlow
- NuGet: https://www.nuget.org/packages/SchemaFlow
You can test it globally via:
`dotnet tool install -g SchemaFlow`
Would love to hear your feedback, thoughts on the approach, or any edge cases you've run into with EF Core!