HoneyDrunk.Data.Migrations 0.7.0

dotnet add package HoneyDrunk.Data.Migrations --version 0.7.0
                    
NuGet\Install-Package HoneyDrunk.Data.Migrations -Version 0.7.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HoneyDrunk.Data.Migrations" Version="0.7.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HoneyDrunk.Data.Migrations" Version="0.7.0" />
                    
Directory.Packages.props
<PackageReference Include="HoneyDrunk.Data.Migrations" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add HoneyDrunk.Data.Migrations --version 0.7.0
                    
#r "nuget: HoneyDrunk.Data.Migrations, 0.7.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package HoneyDrunk.Data.Migrations@0.7.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=HoneyDrunk.Data.Migrations&version=0.7.0
                    
Install as a Cake Addin
#tool nuget:?package=HoneyDrunk.Data.Migrations&version=0.7.0
                    
Install as a Cake Tool

HoneyDrunk.Data.Migrations

Migration tooling conventions for HoneyDrunk.Data. This package provides design-time factory base classes and migration helper utilities.

Purpose

Provides migration infrastructure for:

  • Design-time DbContext factory base class for EF Core tooling
  • Migration runner helpers for CI/CD scenarios
  • Documentation for migration workflows

Usage guidance: This package is intended for tooling and CI/CD workflows. It should not be added as a PackageReference to runtime services or API projects.

Allowed Dependencies

  • HoneyDrunk.Data.Abstractions - For design-time stub dependencies
  • Microsoft.EntityFrameworkCore - For migration APIs
  • Microsoft.EntityFrameworkCore.Design (PrivateAssets=all) - For EF Core tooling
  • HoneyDrunk.Standards - Analyzer package only (PrivateAssets=all)

Note: Database provider configuration (SQL Server, PostgreSQL, etc.) is the responsibility of the derived factory class, not this package.

What Must Never Be Added

  • No database-specific packages - Provider configuration belongs in derived factories
  • No runtime application references - This is for tooling only
  • No transport or auth references - HoneyDrunk.Transport and HoneyDrunk.Auth are not data concerns

Namespace Layout

HoneyDrunk.Data.Migrations
├── Factories/            # Design-time context factory base
│   └── MigrationDbContextFactory.cs
└── Helpers/              # Migration utilities
    └── MigrationRunner.cs

Canonical Workflow

The recommended approach is a dedicated migrations project that contains the design-time factory and owns the migration files.

1. Set up the connection string

# Windows PowerShell
$env:HONEYDRUNK_MIGRATION_CONNECTION = "Server=localhost;Database=MyDb;Trusted_Connection=true;TrustServerCertificate=true"

# Bash
export HONEYDRUNK_MIGRATION_CONNECTION="Server=localhost;Database=MyDb;Trusted_Connection=true;TrustServerCertificate=true"

2. Create a dedicated migrations project

MyApp.Migrations/
├── MyApp.Migrations.csproj
├── MyDbContextFactory.cs
└── Migrations/
    └── (generated migrations)

3. Create a design-time factory

public class MyDbContextFactory : MigrationDbContextFactory<MyDbContext>
{
    protected override void ConfigureOptions(DbContextOptionsBuilder<MyDbContext> optionsBuilder)
    {
        var connectionString = GetConnectionString();
        
        // Provider configuration happens here
        optionsBuilder.UseSqlServer(connectionString, sqlOptions =>
        {
            sqlOptions.MigrationsAssembly(MigrationsAssembly);
        });
    }

    protected override MyDbContext CreateContext(DbContextOptions<MyDbContext> options)
    {
        // Design-time stubs for required dependencies
        // These are not valid for runtime use
        return new MyDbContext(
            options,
            new DesignTimeTenantAccessor(),
            new DesignTimeDiagnosticsContext());
    }
}

// Design-time stubs (include in migrations project)
internal class DesignTimeTenantAccessor : ITenantAccessor
{
    public TenantId GetCurrentTenantId() => default;
}

internal class DesignTimeDiagnosticsContext : IDataDiagnosticsContext
{
    public string? CorrelationId => null;
    public string? OperationId => null;
    public string? NodeId => null;
    public IReadOnlyDictionary<string, string> Tags => new Dictionary<string, string>();
}

Note: Design-time stubs provide minimal implementations for constructor dependencies. They are not valid for runtime use and should only exist in the migrations project.

4. Add a migration

dotnet ef migrations add InitialCreate \
  --project src/MyApp.Migrations \
  --startup-project src/MyApp.Migrations \
  --output-dir Migrations

5. Apply migrations

Development:

dotnet ef database update \
  --project src/MyApp.Migrations \
  --startup-project src/MyApp.Migrations

Production (recommended):

# Generate idempotent script for review
dotnet ef migrations script \
  --project src/MyApp.Migrations \
  --startup-project src/MyApp.Migrations \
  --idempotent \
  --output migrations.sql

# Review and apply via database tooling

Programmatic Migration

For CI/CD scenarios (use with caution—bypasses human review):

await MigrationRunner.ApplyMigrationsAsync(dbContext, cancellationToken);

Check for pending migrations:

if (await MigrationRunner.HasPendingMigrationsAsync(dbContext))
{
    var pending = await MigrationRunner.GetPendingMigrationsAsync(dbContext);
    foreach (var migration in pending)
    {
        Console.WriteLine($"Pending: {migration}");
    }
}

Versioning Guidance

  • Naming: Consider timestamped names (YYYYMMDDHHMMSS_MigrationName) for ordering clarity
  • Reversibility: Pure schema changes (add column, create table) are typically reversible; data transforms and destructive changes (drop column) require explicit rollback strategies
  • Production migrations: Never modify a migration that has been applied to production; create a new migration instead
  • Review: Generate SQL scripts for production deployments to enable human review before execution
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.7.0 91 5/27/2026
0.6.0 103 5/18/2026
0.5.1 101 5/4/2026
0.5.0 89 5/4/2026
0.4.0 114 4/25/2026
0.3.0 122 2/15/2026
0.2.0 117 1/6/2026

v0.7.0: ADR-0011 D11 Sonar cleanup — IUnitOfWork<TContext> exposes ContextType DIM, CorrelationCommandInterceptor switches to a strict allow-list sanitizer, EF naming convention refactored under cognitive-complexity limit. Bumps Kernel 0.7.0→0.8.0, Vault* 0.5.0→0.7.0, Transport 0.6.0→0.7.1, Microsoft.EntityFrameworkCore* and Microsoft.Extensions.* 10.0.7→10.0.8.