Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 30, 2025

AutoReversingMigration throws NotSupportedException when reversing migrations that use Alter.Table().AddColumn(). This worked in 3.3.2 but regressed in 7.1.

// This migration fails to reverse
public class AddColumnsToLibrary : AutoReversingMigration
{
    public override void Up()
    {
        Alter.Table("Library")
            .AddColumn("details_ar").AsString(2000).Nullable()
            .AddColumn("address_ar").AsString(250).Nullable();
    }
}

Root cause: Alter.Table() adds an AlterTableExpression to the context (holding table metadata), then each .AddColumn() adds a CreateColumnExpression. The CreateColumnExpression.Reverse() works correctly, but AlterTableExpression inherited the base class Reverse() which throws.

Changes:

  • Add Reverse() override to AlterTableExpression that returns a copy of itself (metadata-only expression, no reversal semantics needed)
  • Add unit test reproducing the exact issue scenario
  • Add unit test for AlterTableExpression.Reverse() directly

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 57ivsblobprodsu6weus32.blob.core.windows.net
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/11554EEF5C921FE9659F6431188DBD4A/missingpackages_workingdir --packages /home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)
  • 6wovsblobprodsu6weus74.blob.core.windows.net
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/11554EEF5C921FE9659F6431188DBD4A/missingpackages_workingdir --packages /home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)
  • elgvsblobprodsu6weus10.blob.core.windows.net
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/11554EEF5C921FE9659F6431188DBD4A/missingpackages_workingdir --packages /home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)
  • l78vsblobprodsu6weus64.blob.core.windows.net
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/fluentmigrator/fluentmigrator/FluentMigrator.sln --packages /home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot (dns block)
  • mz5vsblobprodsu6weus43.blob.core.windows.net
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/87318DDCF532A56C6C1FB275FEDDD4DC/missingpackages_workingdir --packages /home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/DFC87790DBE2E95C90A1D0F84574FF6C/missingpackages_workingdir --packages /home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/11554EEF5C921FE9659F6431188DBD4A/missingpackages_workingdir --packages /home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)
  • pyvvsblobprodsu6weus63.blob.core.windows.net
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/fluentmigrator/fluentmigrator/FluentMigrator.sln --packages /home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/fluentmigrator/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>AutoReversingMigration on PostgreSQL used to work in 3.3.2 and .NET 8. It stops working on 7.1 and .NET 10.</issue_title>
<issue_description>Describe the bug

[Migration(85)]
public class _0085_AddArabicColumnsToLibraryTable : AutoReversingMigration
{
    public override void Up()
    {
        Alter.Table(Tables.Library)
            .AddColumn("organization_details_ar").AsString(StringLength.TwoThousand).Nullable()
            .AddColumn("details_ar").AsString(StringLength.TwoThousand).Nullable()
            .AddColumn("address_ar").AsString(StringLength.TwoHundredFifty).Nullable();
    }
}

Expected behavior
Reverse migration works

Information (please complete the following information):
.NET 10

    <PackageReference Include="FluentMigrator" Version="7.1.0" />
    <PackageReference Include="FluentMigrator.Runner" Version="7.1.0" />
    <PackageReference Include="FluentMigrator.Runner.Postgres" Version="7.1.0" />
    <PackageReference Include="Npgsql" Version="10.0.0" />
    <PackageReference Include="Npgsql.NetTopologySuite" Version="10.0.0" />

Error

87: _0087_AlterAddIsAffiliateToPersonnelTable reverting
-------------------------------------------------------------------------------
Beginning Transaction
Rolling back transaction
Unhandled exception: System.NotSupportedException: The AlterTableExpression cannot be automatically reversed
   at FluentMigrator.Expressions.MigrationExpressionBase.Reverse()
   at FluentMigrator.AutoReversingMigration.<>c.<GetDownExpressions>b__1_0(IMigrationExpression e)
   at System.Linq.Enumerable.ListSelectIterator`2.Fill(ReadOnlySpan`1 source, Span`1 destination, Func`2 func)
   at System.Linq.Enumerable.ListSelectIterator`2.ToList()
   at System.Linq.Enumerable.ReverseIterator`1.ToList()
   at FluentMigrator.AutoReversingMigration.GetDownExpressions(IMigrationContext context)
   at FluentMigrator.Runner.MigrationRunner.<>c.<ApplyMigrationDown>b__67_0(IMigration m, IMigrationContext c)
   at FluentMigrator.Runner.MigrationRunner.ExecuteMigration(IMigration migration, Action`2 getExpressions)
   at FluentMigrator.Runner.MigrationRunner.ApplyMigrationDown(IMigrationInfo migrationInfo, Boolean useTransaction)
   at FluentMigrator.Runner.MigrationRunner.MigrateDown(Int64 targetVersion, Boolean useAutomaticTransactionManagement)
   at FluentMigrator.Runner.MigrationRunner.MigrateDown(Int64 targetVersion)
   at Program.<<Main>$>g__RollbackDatabase|0_4(IServiceProvider serviceProvider, Int64 rollbackVersion) in D:\GitHub\bias\src\Data\BIAS.Migration\Program.cs:line 105
   at Program.<>c__DisplayClass0_0.<<Main>$>b__1(ParseResult parseResult) in D:\GitHub\bias\src\Data\BIAS.Migration\Program.cs:line 56
   at System.CommandLine.Command.<>c__DisplayClass30_0.<SetAction>b__0(ParseResult context)
   at System.CommandLine.Invocation.AnonymousSynchronousCommandLineAction.Invoke(ParseResult parseResult)
   at System.CommandLine.Invocation.InvocationPipeline.InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
```</issue_description>

<agent_instructions>Also add new tests with a similar use case</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…verse() to AlterTableExpression

Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix AutoReversingMigration issue in PostgreSQL for FluentMigrator Fix AutoReversingMigration for Alter.Table().AddColumn() Nov 30, 2025
Copilot AI requested a review from PhenX November 30, 2025 17:50
@jzabroski jzabroski added this to the 8.0.0 milestone Dec 2, 2025
@github-actions
Copy link

github-actions bot commented Dec 2, 2025

Test Results

    2 files  ±0      2 suites  ±0   38s ⏱️ -1s
5 355 tests ±0  5 023 ✅ +1  332 💤 ±0  0 ❌  - 1 
5 836 runs  ±0  5 240 ✅ +1  596 💤 ±0  0 ❌  - 1 

Results for commit 62c1b28. ± Comparison against base commit fcc42a9.

♻️ This comment has been updated with latest results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AutoReversingMigration on PostgreSQL used to work in 3.3.2 and .NET 8. It stops working on 7.1 and .NET 10.

3 participants