Skip to content

ListMigrations should not warn when current migration is listed #2125

Description

@PhenX

Discussed in #1828

Originally posted by monet820 June 19, 2024
I have a problem understanding why my application is logging a warning.

migrationService.ListMigrations();

info: FluentMigrator.Runner.MigrationRunner[1000]
      Migrations
info: FluentMigrator.Runner.MigrationRunner[1004]
      202307101354: Add_Config
info: FluentMigrator.Runner.MigrationRunner[1004]
      202307110940: Add_Config_v2
info: FluentMigrator.Runner.MigrationRunner[1004]
      202307110950: Add_Objects
info: FluentMigrator.Runner.MigrationRunner[1004]
      202307111000: Add_Structures
warn: FluentMigrator.Runner.MigrationRunner[1001]
      202307111010: Add_Types (current)

Functionality wise, it does not apply the migration again which is correct as it has already been applied, but it logs this as warning when i expect it to be a information as the other migrations.

The migrations are almost identical besides the migration(version) and migration class name


Folder structure

Migrations
    2023
        202307111000_Add_Structures.cs
        202307111010_Add_Types.cs

202307111010_Add_Types.cs

using FluentMigrator;

[Migration(202307111010)]
public class Add_Types : Migration
{
    private const string TableName = "types";

    public override void Up()
    {
        if (!Schema.Table(TableName).Exists())
        {
            Create.Table(TableName)
                .WithColumn("id");
        }
    }

    public override void Down()
    {
        Delete.Table(TableName);
    }
}

        serviceCollection.AddFluentMigratorCore()
            .ConfigureRunner(rb => rb
                .AddPostgres()
                .WithGlobalConnectionString(connectionString)
                .ScanIn(typeof(MigrationManager).Assembly).For.Migrations())
            .BuildServiceProvider(false);

public static class MigrationManager
{
    public static IHost MigrateDatabase(this IHost host)
    {
        using var scope = host.Services.CreateScope();

        var migrationService = scope.ServiceProvider.GetRequiredService<IMigrationRunner>();

        try
        {
            migrationService.ListMigrations();
            migrationService.MigrateUp();
        }
        catch
        {
            //log errors or ...
            throw;
        }

        return host;
    }
}
~~~</div>

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions