Auto migration next vesrion

This commit is contained in:
mborzyszkowski 2020-09-26 18:32:55 +02:00
parent 1443abc391
commit 12e952b0ce
4 changed files with 21 additions and 22 deletions

View File

@ -1,4 +1,3 @@
using System.Threading.Tasks;
using InternshipSystem.Repository;
using Microsoft.AspNetCore.Mvc;

View File

@ -1,4 +1,5 @@
using InternshipSystem.Repository;
using System;
using InternshipSystem.Repository;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Internal;
@ -10,11 +11,24 @@ namespace InternshipSystem.Api.Extensions
{
public static IApplicationBuilder UseMigration(this IApplicationBuilder app)
{
using var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope();
using var context = serviceScope.ServiceProvider.GetService<InternshipPractiseSupervisorDbContext>();
context.Database.Migrate();
bool done = false;
while (!done)
{
try
{
using var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope();
using var context = serviceScope.ServiceProvider.GetService<InternshipPractiseSupervisorDbContext>();
context.Database.Migrate();
done = true;
}
catch (Exception)
{
// ignored
}
}
return app;
}

View File

@ -1,15 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;
using Serilog.Formatting.Compact;
namespace InternshipSystem.Api
{
@ -17,8 +9,6 @@ namespace InternshipSystem.Api
{
public static void Main(string[] args)
{
//TODO: remove ugly solution for to early migration error on startup
Thread.Sleep(10000);
CreateHostBuilder(args).Build().Run();
}

View File

@ -1,9 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using AutoMapper;
using InternshipSystem.Api.Controllers;
using InternshipSystem.Api.Extensions;
@ -11,7 +8,6 @@ using InternshipSystem.Api.ModelBinders;
using InternshipSystem.Api.Options;
using InternshipSystem.Api.Security;
using InternshipSystem.Api.Services;
using InternshipSystem.Core;
using InternshipSystem.Repository;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
@ -64,7 +60,7 @@ namespace InternshipSystem.Api
.AddControllers(o => { o.ModelBinderProviders.Insert(0, new UserBinderProvider()); });
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DatabaseFiller databaseFiller)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseMigration();