Run Migrations on app start

master
dan 2019-07-17 18:07:15 -06:00
parent 8a85e8014a
commit ebe600e94b
3 changed files with 24 additions and 11 deletions

View File

@ -5,7 +5,9 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace OFBButte.Api
@ -14,12 +16,23 @@ namespace OFBButte.Api
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
CreateWebHostBuilder(args).Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
public static IWebHost CreateWebHostBuilder(string[] args)
{
var host = WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseUrls("http://localhost:29021");
.UseUrls("http://localhost:29021")
.Build();
using(var scope = host.Services.CreateScope())
{
var db = scope.ServiceProvider.GetService<Database.OFBContext>();
db.Database.Migrate();
}
return host;
}
}
}

View File

@ -1,13 +1,13 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:50405",
"sslPort": 44314
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
@ -21,10 +21,10 @@
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}

View File

@ -11,6 +11,6 @@
"Environment": "Local"
},
"ConnectionStrings": {
"OFBContext": "server=localhost;database=ofbtest;user=ofbapi;password=87hjdusiodksyeunsjkdis7"
"OFBContext": ""
}
}