Path: redb/redb.Tests.Integration/Fixtures/FixtureWipeGuard.cs Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Tests.Integration/Fixtures/FixtureWipeGuard.cs ---- using redb.Core.Data; namespace redb.Tests.Integration.Fixtures; /// /// Refuses a fixture wipe of a database that does not look like a test database. The fixtures /// clean their database COMPLETELY on start (DELETE FROM _values / _objects) - lawful on the /// dedicated test database, catastrophic on anything else: on 2026-09-10 a freshly seeded /// 100k-object examples database shared the test connection string and was lost to exactly this /// (and the 8M-row cascade-trigger delete масked itself as an hours-long hang first). /// Examples/seeding live in their own databases (redb_examples) since then; this guard is the /// belt to that suspenders. /// public static class FixtureWipeGuard { /// Way above anything the test suites ever create, way below any real seed. public const long MaxObjectsForWipe = 50_000; public static async Task EnsureLooksLikeATestDatabaseAsync(IRedbContext ctx, string fixtureName) { var count = await ctx.ExecuteScalarAsync("SELECT COUNT(*) FROM _objects"); if (count > MaxObjectsForWipe) throw new InvalidOperationException( $"{fixtureName}: refusing to wipe this database - _objects holds {count:N0} rows " + $"(threshold {MaxObjectsForWipe:N0}). It looks seeded or production-like, and the " + "fixture cleanup deletes EVERYTHING. Point the tests at a dedicated test database; " + "the examples seed belongs in redb_examples."); } }