流利的迁移:在Process .net core中运行迁移时如何指定配置文件

编程入门 行业动态 更新时间:2024-10-24 08:19:17
本文介绍了流利的迁移:在Process core中运行迁移时如何指定配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在流畅的迁移器上,根据文档,这是一个有关如何在核心上运行迁移的示例:

On fluent migrator and according to the documentation this is an example on how run migrations in process on core:

using System; using System.Linq; using FluentMigrator.Runner; using FluentMigrator.Runner.Initialization; using Microsoft.Extensions.DependencyInjection; namespace test { class Program { static void Main(string[] args) { var serviceProvider = CreateServices(); // Put the database update into a scope to ensure // that all resources will be disposed. using (var scope = serviceProvider.CreateScope()) { UpdateDatabase(scope.ServiceProvider); } } /// <summary> /// Configure the dependency injection services /// </sumamry> private static IServiceProvider CreateServices() { return new ServiceCollection() // Add common FluentMigrator services .AddFluentMigratorCore() .ConfigureRunner(rb => rb // Add SQLite support to FluentMigrator .AddSQLite() // Set the connection string .WithGlobalConnectionString("Data Source=test.db") // Define the assembly containing the migrations .ScanIn(typeof(AddLogTable).Assembly).For.Migrations()) // Enable logging to console in the FluentMigrator way .AddLogging(lb => lb.AddFluentMigratorConsole()) // Build the service provider .BuildServiceProvider(false); } /// <summary> /// Update the database /// </sumamry> private static void UpdateDatabase(IServiceProvider serviceProvider) { // Instantiate the runner var runner = serviceProvider.GetRequiredService<IMigrationRunner>(); // Execute the migrations runner.MigrateUp(); } } }

如果要加载一个配置文件,如何指定?

How do you specify a profile in case you want to load one?

推荐答案

我找到了它.看最后一行.

I found it. Look at the last line.

return new ServiceCollection() // Add common FluentMigrator services .AddFluentMigratorCore() .ConfigureRunner(rb => rb // Add SQLite support to FluentMigrator .AddSQLite() // Set the connection string .WithGlobalConnectionString("Data Source=test.db") // Define the assembly containing the migrations .ScanIn(typeof(AddLogTable).Assembly).For.Migrations()) .Configure<RunnerOptions>(cfg => { cfg.Profile = profile; })

这在文档中很难找到.发现它被藏在gihub上.

This was wuite difficult to find in the documentation. Found it tucked away in this issue on gihub.

github/fluentmigrator/fluentmigrator/issues/886

更多推荐

流利的迁移:在Process .net core中运行迁移时如何指定配置文件

本文发布于:2023-11-14 00:51:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585769.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:流利   配置文件   net   Process   core

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!