本文介绍了流利的迁移:在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中运行迁移时如何指定配置文件
发布评论