Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration runner code optimization #5476

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions src/Libraries/Nop.Data/NopDbStartup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using FluentMigrator;
using FluentMigrator.Runner;
using FluentMigrator.Runner.Conventions;
Expand All @@ -7,6 +7,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Nop.Core;
using Nop.Core.Infrastructure;
using Nop.Data.Mapping;
using Nop.Data.Migrations;
Expand Down Expand Up @@ -42,9 +43,36 @@ public void ConfigureServices(IServiceCollection services, IConfiguration config
.AddSingleton<IConventionSet, NopConventionSet>()
.AddTransient<IMappingEntityAccessor>(x => x.GetRequiredService<IDataProviderManager>().DataProvider)
.ConfigureRunner(rb =>
rb.WithVersionTable(new MigrationVersionInfo()).AddSqlServer().AddMySql5().AddPostgres()
// define the assembly containing the migrations
.ScanIn(mAssemblies).For.Migrations());
{
var migrationRunnerBuilder = rb.WithVersionTable(new MigrationVersionInfo());
var dataSettings = DataSettingsManager.LoadSettings();
switch (dataSettings.DataProvider)
{
case DataProviderType.SqlServer:
migrationRunnerBuilder.AddSqlServer();
break;
case DataProviderType.MySql:
migrationRunnerBuilder.AddMySql5();
break;
case DataProviderType.PostgreSQL:
migrationRunnerBuilder.AddPostgres();
break;
default:
if (!DataSettingsManager.IsDatabaseInstalled())
{
// This is for the first installation
migrationRunnerBuilder.AddSqlServer().AddMySql5().AddPostgres();
}
else
{
throw new NopException($"Not supported data provider name: '{dataSettings.DataProvider}'");
}
break;
}

// define the assembly containing the migrations
migrationRunnerBuilder.ScanIn(mAssemblies).For.Migrations();
});
}

/// <summary>
Expand All @@ -60,4 +88,4 @@ public void Configure(IApplicationBuilder application)
/// </summary>
public int Order => 10;
}
}
}