(bugfix): version_info table fix

This commit is contained in:
Maksym Sadovnychyy 2026-04-26 22:21:29 +02:00
parent 4fc9cfdcea
commit d7721ff80e
3 changed files with 17 additions and 4 deletions

View File

@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [3.3.20] - 2026-04-26
### Fixed
- **FluentMigrator DI:** **`AddFluentMigratorCore`** registers a default **`IVersionTableMetaDataAccessor`**; **`WithVersionTable`** on **`ConfigureRunner`** could still leave **`VersionInfo`** in use. Engine registration now removes any prior **`IVersionTableMetaDataAccessor`** descriptors and registers **`PassThroughVersionTableMetaDataAccessor`** for **`CertsFluentMigratorVersionTableMetaData`** so **`MigrateUp`** always targets **`version_info`**.
## [3.3.19] - 2026-04-26 ## [3.3.19] - 2026-04-26
### Changed ### Changed

View File

@ -1,4 +1,5 @@
using FluentMigrator.Runner; using FluentMigrator.Runner;
using FluentMigrator.Runner.Initialization;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using MaksIT.CertsUI.Engine.DomainServices; using MaksIT.CertsUI.Engine.DomainServices;
using MaksIT.CertsUI.Engine.FluentMigrations; using MaksIT.CertsUI.Engine.FluentMigrations;
@ -25,15 +26,21 @@ public static class ServiceCollectionExtensions {
if (string.IsNullOrWhiteSpace(certsEngineConfiguration.ConnectionString)) if (string.IsNullOrWhiteSpace(certsEngineConfiguration.ConnectionString))
throw new ArgumentException("Certs engine connection string is required for FluentMigrator (empty string uses connectionless/preview mode and will not create tables).", nameof(certsEngineConfiguration)); throw new ArgumentException("Certs engine connection string is required for FluentMigrator (empty string uses connectionless/preview mode and will not create tables).", nameof(certsEngineConfiguration));
// FluentMigrator: IRunMigrationsService invoked from Program.cs before RunAsync. Use .For.All() so version metadata // FluentMigrator: IRunMigrationsService invoked from Program.cs before RunAsync. Use .For.All() so migration discovery
// and migration discovery match in-process runner expectations (see FluentMigrator docs / #1062). // matches in-process runner expectations (see FluentMigrator docs / #1062).
// Version table: AddFluentMigratorCore registers a default IVersionTableMetaDataAccessor; replace it so public.version_info
// is always used (ConfigureRunner's WithVersionTable alone can lose to that default depending on DI resolution order).
services.AddFluentMigratorCore() services.AddFluentMigratorCore()
.ConfigureRunner(rb => rb .ConfigureRunner(rb => rb
.AddPostgres() .AddPostgres()
.WithGlobalConnectionString(certsEngineConfiguration.ConnectionString) .WithGlobalConnectionString(certsEngineConfiguration.ConnectionString)
.WithVersionTable(new CertsFluentMigratorVersionTableMetaData())
.ScanIn(typeof(BaselineCertsSchema).Assembly).For.All()) .ScanIn(typeof(BaselineCertsSchema).Assembly).For.All())
.AddLogging(lb => lb.AddFluentMigratorConsole()); .AddLogging(lb => lb.AddFluentMigratorConsole());
foreach (var d in services.Where(x => x.ServiceType == typeof(IVersionTableMetaDataAccessor)).ToList())
services.Remove(d);
services.AddSingleton<IVersionTableMetaDataAccessor>(
new PassThroughVersionTableMetaDataAccessor(new CertsFluentMigratorVersionTableMetaData()));
services.AddScoped<IRunMigrationsService, RunMigrationsService>(); services.AddScoped<IRunMigrationsService, RunMigrationsService>();
services.AddScoped<ISchemaSyncService, SchemaSyncService>(); services.AddScoped<ISchemaSyncService, SchemaSyncService>();

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<Version>3.3.19</Version> <Version>3.3.20</Version>
<TargetFramework>net10.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>