Breakwater.Analyzers
0.3.0
dotnet add package Breakwater.Analyzers --version 0.3.0
NuGet\Install-Package Breakwater.Analyzers -Version 0.3.0
<PackageReference Include="Breakwater.Analyzers" Version="0.3.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="Breakwater.Analyzers" Version="0.3.0" />
<PackageReference Include="Breakwater.Analyzers"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Breakwater.Analyzers --version 0.3.0
#r "nuget: Breakwater.Analyzers, 0.3.0"
#:package Breakwater.Analyzers@0.3.0
#addin nuget:?package=Breakwater.Analyzers&version=0.3.0
#tool nuget:?package=Breakwater.Analyzers&version=0.3.0
Breakwater
Roslyn analyzer that catches unsafe EF Core migrations before production does.
dotnet ef migrations add happily generates a DropColumn, a RenameColumn,
a CreateIndex that locks the table, or an AlterColumn that fails on
existing data — and nothing warns you. Breakwater reads the migration when
you build and tells you before production does.
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(name: "Email", table: "Users");
}
warning BW001: DropColumn 'Users.Email' loses data and breaks application
versions that still read the column
Install
dotnet add package Breakwater.Analyzers
The package is not yet published to nuget.org (release is pending). Once
published, this adds one line to your .csproj:
<PackageReference Include="Breakwater.Analyzers" Version="0.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
The package contains only the analyzer: zero runtime dependencies, nothing ships in your build output. It works with any EF Core provider; provider-aware rules currently recognize SQL Server, PostgreSQL, SQLite and MySQL.
See the tutorial for a full walkthrough: install, first warning, where results show up, reading and acting on a result, CI, and every possible outcome.
Rules
Only a migration's Up method is analyzed; Down is ignored (except BW011,
which looks at Down itself). Each rule has a page under
docs/rules/ with the full "why it hurts" explanation and a
safe alternative.
breakwater_profile (see Configure) controls which tier is
active: Warning and Suggestion rules run under the default
recommended profile; Strict-only rules are silent unless
breakwater_profile = strict is set.
| Id | Trigger | Default tier |
|---|---|---|
| BW001 | DropColumn |
Warning |
| BW002 | DropTable |
Warning |
| BW003 | RenameColumn, RenameTable |
Warning |
| BW004 | AlterColumn type change, length/precision narrowing |
Warning |
| BW005 | AlterColumn nullable to not-null without a default |
Warning |
| BW006 | AddColumn not-null without a default on an existing table |
Warning |
| BW007 | CreateIndex on an existing table without a concurrent/online annotation |
Warning |
| BW008 | AddForeignKey / AddCheckConstraint on an existing table |
Warning |
| BW009 | AddUniqueConstraint / AddPrimaryKey on an existing table |
Warning |
| BW010 | Raw Sql(...): UPDATE/DELETE without WHERE, TRUNCATE, DROP |
Warning |
| BW011 | Down is empty or throws NotSupportedException |
Strict-only |
| BW012 | InsertData / UpdateData / DeleteData with many rows |
Suggestion |
| BW013 | Schema change and data change in the same migration | Suggestion |
| BW014 | Provider-specific type change (e.g. Postgres enum-like type) | Suggestion |
| BW015 | AlterColumn collation change |
Warning |
| BW016 | Postgres AddColumn with a volatile default (now(), gen_random_uuid()) |
Warning |
| BW017 | DropPrimaryKey, DropUniqueConstraint, DropCheckConstraint, DropForeignKey |
Suggestion |
| BW018 | DropSchema, DropSequence, AlterSequence / RestartSequence |
Suggestion |
| BW019 | Raw Sql on Postgres: CREATE INDEX without CONCURRENTLY, LOCK TABLE, VACUUM FULL, unsafe ALTER TABLE ... SET DATA TYPE |
Warning |
| BW020 | Postgres DDL migration without SET lock_timeout |
Strict-only |
| BW021 | AlterDatabase (collation, edition) |
Suggestion |
| BW022 | Migration mixes several risky operations on the same table | Suggestion |
| BW023 | DropColumn and AddColumn on the same table (likely an undetected rename) |
Warning |
| BW024 | DeleteData (often from removing/changing HasData seed rows) |
Warning |
| BW025 | AddForeignKey on a column added in the same migration with a placeholder default |
Warning |
| BW026 | AlterColumn that adds or removes identity/value generation |
Warning |
| BW027 | CreateIndex with unique: true on an existing table |
Suggestion |
| BW028 | Migration class missing [Migration("id")], or duplicate migration ids |
Warning |
| BW029 | suppressTransaction: true, or MySQL migration with several operations |
Suggestion |
| BW030 | AddForeignKey with onDelete: Cascade |
Strict-only |
| BW031 | Raw Sql containing GO, USE, or other client-side batch separators |
Warning |
| BW032 | Database.EnsureCreated() in a project that also has migrations |
Warning |
| BW033 | Raw Sql that creates a login/user with a password, or embeds a connection string |
Warning |
| BW034 | Raw Sql that disables a safety check (NOCHECK CONSTRAINT, DISABLE TRIGGER, SET FOREIGN_KEY_CHECKS=0, DROP DATABASE) |
Warning |
| BW035 | Raw Sql: ALTER TABLE ... DROP COLUMN, or ADD COLUMN ... NOT NULL with no DEFAULT |
Warning |
| BW036 | Raw Sql: DROP PROCEDURE/FUNCTION/VIEW IF EXISTS immediately followed by a matching CREATE (idempotent redefinition) |
Suggestion |
| BW037 | Raw Sql: CREATE TABLE/CREATE INDEX with no IF NOT EXISTS guard (non-idempotent) |
Suggestion |
BW999 is not a migration rule: it reports if a rule itself throws, so a bug
in Breakwater surfaces as a low-severity diagnostic instead of crashing your
build.
Configure
Profile — breakwater_profile in .editorconfig switches on the
strict-only rules (BW011, BW020, BW030), which are silent by default because
they are too common or too opinionated for most teams:
[*.cs]
breakwater_profile = strict
Per-rule severity — any rule's severity can be changed or turned off the usual Roslyn way:
# Fail the build on data loss
dotnet_diagnostic.BW001.severity = error
# Turn a rule off entirely
dotnet_diagnostic.BW017.severity = none
Suppress one call with a reason — put a comment on the line above the flagged call:
// breakwater: allow BW001 Email column has been unused since v2.3, safe to drop
migrationBuilder.DropColumn(name: "Email", table: "Users");
A reason is required; an empty or missing reason leaves the diagnostic in
place and appends a note asking for one. #pragma warning disable BW001 and
[SuppressMessage("Migration", "BW001")] also work, the same as any other
analyzer.
Provider — breakwater_provider names the database when it can't be
inferred (an explicit if (migrationBuilder.IsNpgsql()) guard, or a chained
Npgsql:/SqlServer:/MySql:/Sqlite: annotation, are both auto-detected
without this). Setting it makes every provider-specific rule
(BW007, BW014, BW016, BW019, BW020, BW029, BW031) fire without
needing that guard, since most real migrations never write one:
breakwater_provider = postgres # sqlserver | postgres | sqlite | mysql | auto (default)
Deploy model — breakwater_deploy_model = downtime_ok downgrades
BW001/BW002/BW003 (the removal rules) to Info, for a project that
accepts downtime during a deploy and doesn't need the rolling-deploy
warning:
breakwater_deploy_model = downtime_ok # rolling (default) | downtime_ok
Adopting an existing project — breakwater_since_migration skips every
migration at or before a given id entirely, so years of existing production
migrations aren't all flagged at once the day the package is added:
breakwater_since_migration = 20260101000000_LastMigrationBeforeBreakwater
Small tables — breakwater_small_tables (comma-separated, case
insensitive) downgrades the table-lock/lock-duration rules to Info for
tables you know are small enough that a lock is harmless:
breakwater_small_tables = FeatureFlags, AppSettings
Breakwater.Tool (breakwater-sql)
A companion dotnet tool that lints the SQL script dotnet ef migrations script produces — the same unsafe shapes the analyzer catches in inline
Sql(...) calls, but against the final provider-specific SQL, so detection
is provider-accurate instead of guess-based.
dotnet tool install --global Breakwater.Tool
dotnet ef migrations script --output migrations.sql
breakwater-sql migrations.sql --provider postgres
--provider is required (sqlserver, postgres, sqlite, mysql) since a
generated script has no C# guard to detect it from. --format table|json|sarif
switches output format; table is the default. --format sarif emits a
minimal SARIF 2.1.0 log (one run, one result per finding) for feeding
GitHub code scanning, the same way the analyzer's own
-p:ErrorLog=...;version=2 output does.
breakwater-sql init prints a starter .editorconfig snippet listing every
breakwater_* key from Configure, commented out:
breakwater-sql init .editorconfig
Refuses to overwrite an existing file unless --force is passed; with no
path, it prints to stdout instead.
Use breakwater in CI on your own repo
Breakwater comments on its own PRs with a summary of findings on changed
files (see .github/workflows/pr-review.yml). That mechanism is packaged as
a reusable composite GitHub Action — see
.github/actions/pr-comment for the inputs, a
full example workflow, and the honest limitations (it requires your project
to already reference Breakwater.Analyzers, and it isn't published/tagged
yet, same pre-release status as the package above).
Testing and feedback
Breakwater is pre-release and could use real-world testing on real EF Core projects. If you try it and hit a false positive, a missed case, a rule that doesn't make sense, or anything else that's off, please open an issue — feedback on what's missing or not working is very welcome.
Help wanted
This is a one-person project. If you like what Breakwater does and want to pitch in — trying it on your own migrations, adding a rule, improving docs, anything — it's very welcome. Even just running it and reporting back what you found (good or bad) helps a lot.
License
MIT
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.