【问题标题】:FluentMigrator generate SQL Output from In-Process Migration runnerFluentMigrator 从 In-Process Migration 运行器生成 SQL 输出
【发布时间】:2020-01-25 16:12:57
【问题描述】:

有没有办法使用In-Process Migration Runner 生成SQL 文件输出,类似于使用dotnet-fm 工具中的-output command argument 可以实现的功能。

我在IMigrationRunnerIMigrationRunnerBuilderIMigrationProcessorOptions 中找不到任何可以设置配置输出的属性、字段或方法。

我错过了什么吗?

【问题讨论】:

    标签: c# database-migration fluent-migrator


    【解决方案1】:

    https://fluentmigrator.github.io/api/v3.x/FluentMigrator.Runner.Logging.FluentMigratorConsoleLoggerProvider.html 本页介绍了如何在 fluent 迁移器中使用日志记录提供程序。

    https://fluentmigrator.github.io/api/v3.x/FluentMigrator.Runner.Logging.LogFileFluentMigratorLoggerOptions.html 在这里,您可以查看不同的选项,例如将日志写入 SQL 数据库或文件,或者仅在控制台中显示 SQL(如果您使用控制台日志提供程序)。

    这是怎么做的:

    services
        .AddSingleton<ILoggerProvider, LogFileFluentMigratorLoggerProvider>()
        .Configure<LogFileFluentMigratorLoggerOptions>(
            opt =>
            {
                opt.OutputFileName = options.OutputFileName;
                opt.OutputGoBetweenStatements = targetIsSqlServer;
                opt.ShowSql = true;
            });
    

    您还可以编写扩展方法和装饰器来添加自定义日志记录提供程序,以防您想在控制台以外的地方记录它。但我相信 fluentMigrator 已经支持这个开箱即用。

    【讨论】:

    • 问题不在于EF。按照链接到 Fluentmigrator
    • 哦,忽略了这一点,我的错。但即便如此,EF 和 FluentMigrator 都提供了连接日志提供程序的方法。我将编辑我的答案
    • 这实际上是一个聪明的想法,困难的部分是为实际的 sql 语句过滤每条日志消息
    • 您可以查看日志记录提供程序,并编写您自己的实现,在其中过滤这些 sql 语句。我认为这将很难,但您可以查看文档
    猜你喜欢
    • 2013-01-18
    • 1970-01-01
    • 2018-07-21
    • 1970-01-01
    • 2015-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-17
    相关资源
    最近更新 更多