jbogard/Respawn
jbogard/Respawn has 3,027 GitHub stars and 153 forks. GitHot measured -1 stars in 24 hours and 0 in 7 days. Last checked 2026-11-11 07:38 UTC. Last push 2026-01-19.
Intelligent database cleaner for integration tests
实测星标增长
- 24小时
- -1
- 7天
- 0
- 15天
- 更新延迟
- 1个月
- 更新延迟
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Respawn
Respawn is a small utility to help in resetting test databases to a clean state. Instead of deleting data at the end of a test or rolling back a transaction, Respawn resets the database back to a clean, empty state by intelligently deleting data from tables.
To use, create a Respawner and initialize with tables you want to skip, or schemas you want to keep/ignore:
var respawner = await Respawner.CreateAsync(connection, new RespawnerOptions
{
TablesToIgnore = new Table[]
{
"sysdiagrams",
"tblUser",
"tblObjectType",
new Table("MyOtherSchema", "MyOtherTable")
},
SchemasToExclude = new []
{
"RoundhousE"
}
});
Or if you want to use a different database:
var respawner = await Respawner.CreateAsync(connection, new RespawnerOptions
{
SchemasToInclude = new []
{
"public"
},
DbAdapter = DbAdapter.Postgres // 👈 optional, inferred from the connection for SQL Server, PostgreSQL, MySQL, Oracle and Informix
});
In your tests, in the fixture setup, reset to a clean state:
await respawner.ResetAsync("MyConnectionStringName");
or if you're using a database besides SQL Server, pass an open DbConnection:
using (var conn = new NpgsqlConnection("ConnectionString"))
{
await conn.OpenAsync();
await respawner.ResetAsync(conn);
}
How does it work?
Respawn examines the SQL metadata intelligently to build a deterministic order of tables to delete based on foreign key relationships between tables. It navigates these relationships to build a DELETE script starting with the tables with no relationships and moving inwards until all tables are accounted for.
Once this in-order list of tables is created in the CreateAsync factory, the Respawner object keeps this list of tables privately so that the list of tables and the order is only calculated once.
In your tests, you Reset your database before each test run. If there are any tables/schemas that you don't want to be cleared out, include these in the configuration of your RespawnerOptions.
In benchmarks, a deterministic deletion of tables is faster than truncation, since truncation requires disabling or deleting foreign key constraints. Deletion results in easier test debugging/maintenance, as transaction rollbacks/post-test deletion still rely on that mechanism at the beginning of each test. If data comes in from another source, your test might fail. Respawning to a clean state assures you have a known starting point before each test.
Installing Respawn
You should install Respawn with NuGet:
Install-Package Respawn
Or via the .NET Core CLI:
dotnet add package Respawn
This command from Package Manager Console will download and install Respawn.
Local development
To install and run local dependencies needed for tests, (PostgreSQL and MySQL) install Docker for Windows and from the command line at the solution root run:
docker-compose up -d
This will pull down the latest container images and run them. You can then run the local build/tests.
探索相关项目
Asabeneh/30-Days-Of-Python
30 Days of Python 编程挑战是一份循序渐进的指南,用于在 30 天内学习 Python 编程语言。这项挑战可能需要超过 100 天。请按自己的节奏进行。这些视频或许也有帮助:https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,560 星标grafana/grafana
开放且可组合的可观测性与数据可视化平台。可对来自 Prometheus、Loki、Elasticsearch、InfluxDB、Postgres 等众多数据源的指标、日志和追踪进行可视化。
77,830 星标redis/redis
对于正在构建实时数据驱动应用的开发者而言,Redis 是首选、速度最快且功能最丰富的缓存、数据结构服务器和文档与向量查询引擎。
77,395 星标apache/superset
Apache Superset 是一个数据可视化与数据探索平台
75,473 星标