PANiXiDA.Core.Ef.Migrator
1.0.2
dotnet add package PANiXiDA.Core.Ef.Migrator --version 1.0.2
NuGet\Install-Package PANiXiDA.Core.Ef.Migrator -Version 1.0.2
<PackageReference Include="PANiXiDA.Core.Ef.Migrator" Version="1.0.2" />
<PackageVersion Include="PANiXiDA.Core.Ef.Migrator" Version="1.0.2" />
<PackageReference Include="PANiXiDA.Core.Ef.Migrator" />
paket add PANiXiDA.Core.Ef.Migrator --version 1.0.2
#r "nuget: PANiXiDA.Core.Ef.Migrator, 1.0.2"
#:package PANiXiDA.Core.Ef.Migrator@1.0.2
#addin nuget:?package=PANiXiDA.Core.Ef.Migrator&version=1.0.2
#tool nuget:?package=PANiXiDA.Core.Ef.Migrator&version=1.0.2
PANiXiDA.Core.Ef.Migrator
PANiXiDA.Core.Ef.Migrator is a .NET library for automatically creating and applying Entity Framework Core migrations when an application starts.
It is designed for services that use PostgreSQL with EF Core and need a controlled startup-time migration flow for development, test, or managed deployment scenarios.
Status
Overview
The package extends IHostBuilder with a migration startup step. It builds the host, resolves the configured DbContext, detects pending model changes, optionally scaffolds a new EF Core migration into the target project, and optionally applies existing and generated migrations to PostgreSQL.
This package is intentionally small: the public entry point is RunMigrationsAsync<TContext>(), while generation and application behavior is controlled through configuration.
Features
- Detects differences between the current
DbContextmodel and the latest model snapshot. - Generates migration files into a configured project directory.
- Applies compiled pending migrations.
- Applies a newly generated migration in the same startup flow.
- Supports disabling generation and applying independently.
- Uses PostgreSQL through
Npgsql.EntityFrameworkCore.PostgreSQL.
Quick Start
Requirements
- .NET 10 SDK
- Entity Framework Core 10
- PostgreSQL
Installation
<ItemGroup>
<PackageReference Include="PANiXiDA.Core.Ef.Migrator" Version="1.0.1" />
</ItemGroup>
Minimal import
using PANiXiDA.Core.Ef.Migrator;
First example
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Hosting;
using PANiXiDA.Core.Ef.Migrator;
var builder = Host
.CreateDefaultBuilder(args)
.ConfigureServices((context, services) =>
{
services.AddDbContext<AppDbContext>(options =>
{
options.UseNpgsql(
context.Configuration["PostgreSqlConnectionString"],
npgsql => npgsql.MigrationsAssembly(typeof(AppDbContext).Assembly.GetName().Name));
});
});
using var host = await builder.RunMigrationsAsync<AppDbContext>();
await host.RunAsync();
Usage
Configuration
The migration flow is controlled by these configuration values:
| Key | Required | Default | Description |
|---|---|---|---|
GenerateMigrations |
No | true |
Enables creating a migration when the model differs from the latest snapshot. |
ApplyMigrations |
No | true |
Enables applying compiled pending migrations and the newly generated migration. |
Ef:ProjectPath |
Yes, when generation is enabled and differences exist | None | Absolute or relative path to the project where migration files should be written. |
Ef:MigrationsDirectory |
Yes, when generation is enabled and differences exist | None | Migration output directory inside Ef:ProjectPath. |
Example appsettings.json:
{
"GenerateMigrations": true,
"ApplyMigrations": true,
"Ef": {
"ProjectPath": ".",
"MigrationsDirectory": "Data/Migrations"
},
"PostgreSqlConnectionString": "Host=localhost;Database=app;Username=app;Password=app"
}
Generate but do not apply
{
"GenerateMigrations": true,
"ApplyMigrations": false,
"Ef": {
"ProjectPath": ".",
"MigrationsDirectory": "Data/Migrations"
}
}
Apply existing migrations only
{
"GenerateMigrations": false,
"ApplyMigrations": true
}
Disable startup migrations
{
"GenerateMigrations": false,
"ApplyMigrations": false
}
Behavior Notes
RunMigrationsAsync<TContext>()returns the builtIHost.- When generation is disabled and applying is enabled, only compiled pending migrations are applied.
- When generation is enabled but there are no model differences, the package applies compiled migrations with EF Core
MigrateAsync()if applying is enabled. - When generation and applying are both disabled, the host is built and returned without migration work.
Ef:MigrationsDirectorymust point to a directory insideEf:ProjectPath.
Project Structure
.
|-- src/
| `-- PANiXiDA.Core.Ef.Migrator/
|-- tests/
| `-- PANiXiDA.Core.Ef.Migrator.IntegrationTests/
|-- .github/
| `-- workflows/
| `-- ci.yml
|-- Directory.Build.props
|-- Directory.Build.targets
|-- Directory.Packages.props
|-- global.json
|-- version.json
|-- LICENSE
`-- README.md
Development
Build
dotnet restore
dotnet build --configuration Release
Format
dotnet format
Test
dotnet test --configuration Release
Integration tests use Testcontainers and require a working Docker environment.
Pack
dotnet pack --configuration Release
Full local validation
dotnet restore
dotnet format
dotnet build --configuration Release
dotnet test --configuration Release
dotnet pack --configuration Release
Tooling and Conventions
This repository uses:
- .NET 10
- Nullable enabled
- Implicit usings enabled
- Central package management
- Microsoft Testing Platform
- xUnit v3
- FluentAssertions
- Testcontainers for PostgreSQL integration tests
- Nerdbank.GitVersioning
- GitHub Actions
License
This project is licensed under the Apache-2.0 license.
See the LICENSE file for details.
Maintainers
Maintained by PANiXiDA.
For questions or improvements, use GitHub Issues or Pull Requests.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.EntityFrameworkCore (>= 10.0.5)
- Microsoft.EntityFrameworkCore.Design (>= 10.0.5)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.5)
- Microsoft.Extensions.Configuration.Json (>= 10.0.5)
- Microsoft.Extensions.Hosting (>= 10.0.5)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 10.0.1)
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 |
|---|---|---|
| 1.0.2 | 94 | 5/7/2026 |