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 trans

Search code, repositories, users, issues, pull requests...

submited by
Style Pass
2024-04-18 03:30:06

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.

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.

Leave a Comment