Fluent migrator error on start from bin/Debug folder

98 Views Asked by At

I have API where I used FluentMigrator for Dapper Migrations. Now, when I try to run built .exe from bin folder, there is the exception:

2023-08-23 11:46:49.480 [INF] 1: _1_InitialMigration migrating !!! Method is not supported by the connectionless processor 2023-08-23 11:46:49.487 [FTL] Fatal error System.NotImplementedException: Method is not supported by the connectionless processor at FluentMigrator.Runner.Processors.ConnectionlessProcessor.SchemaExists(String schemaName) at FluentMigrator.Builders.Schema.Schema.SchemaSchemaQuery.Exists() at SMC.Backup.Infrastructure.Database.Migrations._1_InitialMigration.Up() in D:\ProtelionProjects\smc-backup\Source\SMC.Backup.Infrastructure\Database\Migrations\1_InitialMigration.cs:line 17 at FluentMigrator.MigrationBase.GetUpExpressions(IMigrationContext context) at FluentMigrator.Runner.MigrationRunner.<>c.b__69_0(IMigration m, IMigrationContext c) at FluentMigrator.Runner.MigrationRunner.ExecuteMigration(IMigration migration, Action2 getExpressions) at FluentMigrator.Runner.MigrationRunner.ApplyMigrationUp(IMigrationInfo migrationInfo, Boolean useTransaction) at FluentMigrator.Runner.MigrationRunner.MigrateUp(Int64 targetVersion, Boolean useAutomaticTransactionManagement) at FluentMigrator.Runner.MigrationRunner.MigrateUp(Boolean useAutomaticTransactionManagement) at FluentMigrator.Runner.MigrationRunner.MigrateUp() at SMC.Backup.Infrastructure.ServiceCollectionExtensions.Migrate(IApplicationBuilder app) in D:\ProtelionProjects\smc-backup\Source\SMC.Backup.Infrastructure\ServiceCollectionExtensions.cs:line 62 at SMC.Backup.Host.Startup.Configure(IApplicationBuilder app) in D:\ProtelionProjects\smc-backup\Source\SMC.Backup.Host\Startup.cs:line 80 at System.RuntimeMethodHandle.InvokeMethod(Object target, Span1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder) at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.b__0(IApplicationBuilder builder)

I've created Migration class which looks like this

[Migration(1)]
public class _1_InitialMigration : Migration
{
    public override void Down()
    {
        Delete.Table("backups");

        Delete.Schema("public");
    }
    public override void Up()
    {
        // Check if the database exists
        if (!Schema.Schema("public").Exists())
        {
            // Create the database
            Create.Schema("public");
        }

        if (!Schema.Table("backups").Exists())
        {
            Create.Table("backups")
            .WithColumn("id").AsInt32().PrimaryKey().Identity()
            .WithColumn("launch_mode").AsInt16().NotNullable()
            .WithColumn("status").AsInt16().NotNullable().Indexed()
            .WithColumn("started_at").AsDateTime().NotNullable()
            .WithColumn("finished_at").AsDateTime().Nullable()
            .WithColumn("error_message").AsString().Nullable();
        }
    }
}

And I have created extension class where I'm injecting FluentMigrator and using in my API startup class.

public static IServiceCollection AddFluentMigrator(this IServiceCollection services, IConfiguration configuration)
{
    services.AddFluentMigratorCore()
            .ConfigureRunner(rb => rb
                .AddPostgres()
                .WithGlobalConnectionString(configuration.GetConnectionString("DefaultConnection"))
                .ScanIn(typeof(_1_InitialMigration).Assembly).For.Migrations())
            .AddLogging(lb => lb.AddFluentMigratorConsole());

    return services;
}
public static IApplicationBuilder Migrate(this IApplicationBuilder app)
{
    using var scope = app.ApplicationServices.CreateScope();
    var migrator = scope.ServiceProvider.GetService<IMigrationRunner>();
    migrator?.ListMigrations();
    migrator?.MigrateUp();
    return app;
}

Why it happens and how to fix if it's really problem in fluent migrator usage?

Thanks in advance.

I've tried to find soluiton in FluentMigrator GitHub issues. But I got no reply.

0

There are 0 best solutions below