Respawn.Postgres
1.0.0
See the version list below for details.
dotnet add package Respawn.Postgres --version 1.0.0
NuGet\Install-Package Respawn.Postgres -Version 1.0.0
<PackageReference Include="Respawn.Postgres" Version="1.0.0" />
paket add Respawn.Postgres --version 1.0.0
#r "nuget: Respawn.Postgres, 1.0.0"
// Install Respawn.Postgres as a Cake Addin #addin nuget:?package=Respawn.Postgres&version=1.0.0 // Install Respawn.Postgres as a Cake Tool #tool nuget:?package=Respawn.Postgres&version=1.0.0
Respawn.Postgres
Builds upon Jimmy Bogard's Respawn and provides enhanced performance for Postgres databases. Respawn is an intelligent database cleaner for integration tests.
Introduction
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 checkpoint by intelligently deleting data from tables.
Please refer to Respawn on GitHub for more information about the innards of Respawn.
I was using Respawn a while ago to reset a Postgres database in a project of mine during integration testing. I was a little disappointed by its performance though, seeing running times of around 13 seconds to clear a 52 table database that didn't even contain any data to begin with.
After doing some research, I concluded that the best approach would be using Postgres' CREATE DATABASE dbname TEMPLATE template
(see Template Databases in the PostgreSQL Manual).
In my case, this reduced the time to reset the database to a clean state to less than a second, which is about 13 times faster! I have to note though that the first run still takes 13 seconds but subsequent runs take advantage of the cached database and like I said, that takes less than a second.
Requirements
These are some requirements that apply in addition to vanilla Respawn.
- The
dblink
Postgres extension is required to be installed in your database. ThePostgresCheckpoint.AutoCreateExtensions
property can be set totrue
to automatically install the required extension(s).
Implications
Please make sure you understand the following implications and then decide whether you still want to use this library.
- A cache version of your database will be created.
- Existing connections to either the database or the cached database may be dropped during the process. Any open connections in the ADO.NET connection pool will be corrupted as a result of this so the connection pool will be reset as well to counter that issue.
Usage
To use, create a PostgresCheckpoint
and initialize with tables you want to skip, or schemas you want to keep/ignore:
private static PostgresCheckpoint checkpoint = new PostgresCheckpoint
{
AutoCreateExtensions = true,
SchemasToInclude = new[]
{
"public"
}
};
In your tests, in the fixture setup, reset your checkpoint:
await checkpoint.Reset("MyConnectionString");
Installing Respawn.Postgres
You should install Respawn.Postgres with NuGet:
Install-Package Respawn.Postgres
Or via the .NET Core CLI:
dotnet add package Respawn.Postgres
This command from Package Manager Console will download and install Respawn.Postgres.
Local development
To install and run local dependencies needed for integration tests (PostgreSQL), 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.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.3 is compatible. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net452 is compatible. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5.2
- Npgsql (>= 3.2.7)
- Respawn (>= 3.0.1)
- System.ValueTuple (>= 4.5.0)
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.1)
- Npgsql (>= 3.2.7)
- Respawn (>= 3.0.1)
- System.Data.Common (>= 4.3.0)
- System.Linq (>= 4.3.0)
- System.Runtime.Extensions (>= 4.3.0)
- System.ValueTuple (>= 4.5.0)
-
.NETStandard 2.0
- Npgsql (>= 3.2.7)
- Respawn (>= 3.0.1)
- System.ValueTuple (>= 4.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.