Hyperbee.Migrations.Providers.Postgres
1.2.7-develop.240430153808
See the version list below for details.
dotnet add package Hyperbee.Migrations.Providers.Postgres --version 1.2.7-develop.240430153808
NuGet\Install-Package Hyperbee.Migrations.Providers.Postgres -Version 1.2.7-develop.240430153808
<PackageReference Include="Hyperbee.Migrations.Providers.Postgres" Version="1.2.7-develop.240430153808" />
paket add Hyperbee.Migrations.Providers.Postgres --version 1.2.7-develop.240430153808
#r "nuget: Hyperbee.Migrations.Providers.Postgres, 1.2.7-develop.240430153808"
// Install Hyperbee.Migrations.Providers.Postgres as a Cake Addin #addin nuget:?package=Hyperbee.Migrations.Providers.Postgres&version=1.2.7-develop.240430153808&prerelease // Install Hyperbee.Migrations.Providers.Postgres as a Cake Tool #tool nuget:?package=Hyperbee.Migrations.Providers.Postgres&version=1.2.7-develop.240430153808&prerelease
Hyperbee Migrations Postgres Provider
Welcome to Hyperbee.Migrations.Providers.Postgres
, an extension to the foundational Hyperbee.Migrations
library. This extension is specifically designed to incorporate support for Postgres.
Introduction
The Hyperbee.Migrations.Providers.Postgres
library is an tool for developers seeking to perform database migrations in a Postgres environment using the Hyperbee.Migrations
library. This library furnishes a comprehensive suite of tools and functionalities that integrate effortlessly with Hyperbee.Migrations
, thereby enabling developers to harness the robust capabilities of Postgres in their applications.
The Hyperbee.Migrations.Providers.Postgres
library is equipped to assist developers in creating, updating, and managing their Postgres databases. With the aid of this library, developers can concentrate their efforts on the development of their application, while the library handles the intricacies of database management.
We are committed to continuous improvement and feature enhancement. We appreciate your interest and look forward to your valuable feedback.
Please see Hyperbee Migrations' Read Me for non-database specific usage.
Configuration
Add Postgres Services
// In Startup.cs
public void ConfigureServices(IServiceCollection services)
{
// Configure Postgres
services.AddNpgsqlDataSource( connectionString );
// Add the MigrationRunner
services.AddPostgresMigrations(...);
}
public void Configure(IApplicationBuilder app, ...)
{
// Run pending migrations.
var migrationService = app.ApplicationServices.GetRequiredService<MigrationRunner>();
migrationService.Run();
}
Preventing simultaneous migrations
By default, Hyperbee Migrations prevents parallel migration runner execution. If you have 2 instances of your app running, and both try to run migrations, Hyperbee Migrations will prevent the second instance from running migrations and will log a warning.
Hyperbee Migrations accomplishes this by using a distributed lock at the database layer. The default implementation is based on the provider and uses a timeout and an auto-renewal interval to prevent orphaned locks.
If you want to change this behavior you can override the default options:
services.AddPostgresDBMigrations( options =>
{
// Locking is on by default. Set to false to allow simultaneous runners - but don't be that guy.
options.LockingEnabled = false;
// You can change locking behavior. Defaults shown.
options.LockMaxLifetime = TimeSpan.FromMinutes( 1 ); // max time-to-live
options.LockName = "ledger"
});
Dependency Injection
The Postgres provider also provides a PostgresResourceRunner<MyMigration>
that adds helpful functionality when using embedded resources.
SqlFromAsync
runs sql statements and can do any sort of updates supported by PostgresAllSqlFromAsync
runs all the embedded resources with the resource named matching the Migration. See 1000-Initial as an example
[Migration(1)]
public class MyMigration : Migration
{
private readonly MongoDBResourceRunner<MyMigration> _resourceRunner;
public CreateInitialBuckets( MongoDBResourceRunner<MyMigration> resourceRunner )
{
_resourceRunner = resourceRunner;
}
public override async Task UpAsync( CancellationToken cancellationToken = default )
{
// run a `resource` migration to create initial state.
await resourceRunner.SqlFromAsync( [
"1-MyMigration.sql"
], cancellationToken );
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- Hyperbee.Migrations (>= 1.0.0-develop.240430153808)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Hosting (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- Npgsql (>= 8.0.2)
- Npgsql.DependencyInjection (>= 8.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.0.0 | 88 | 11/21/2024 |
2.0.0-develop.241121151205 | 43 | 11/21/2024 |
1.2.7 | 138 | 4/30/2024 |
1.2.7-develop.240430153808 | 68 | 4/30/2024 |
1.2.7-develop.240430124929 | 58 | 4/30/2024 |