diff --git a/src/InternshipSystem.Api/Controllers/AdminController.cs b/src/InternshipSystem.Api/Controllers/AdminController.cs index e929e79..9b5b592 100644 --- a/src/InternshipSystem.Api/Controllers/AdminController.cs +++ b/src/InternshipSystem.Api/Controllers/AdminController.cs @@ -1,4 +1,3 @@ -using System.Threading.Tasks; using InternshipSystem.Repository; using Microsoft.AspNetCore.Mvc; diff --git a/src/InternshipSystem.Api/Extensions/ApplicationBuilderExtensions.cs b/src/InternshipSystem.Api/Extensions/ApplicationBuilderExtensions.cs index 4f53406..5dffba4 100644 --- a/src/InternshipSystem.Api/Extensions/ApplicationBuilderExtensions.cs +++ b/src/InternshipSystem.Api/Extensions/ApplicationBuilderExtensions.cs @@ -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().CreateScope(); - using var context = serviceScope.ServiceProvider.GetService(); - - context.Database.Migrate(); - + bool done = false; + while (!done) + { + try + { + using var serviceScope = app.ApplicationServices.GetRequiredService().CreateScope(); + using var context = serviceScope.ServiceProvider.GetService(); + + context.Database.Migrate(); + + done = true; + } + catch (Exception) + { + // ignored + } + } + return app; } diff --git a/src/InternshipSystem.Api/Program.cs b/src/InternshipSystem.Api/Program.cs index 052d137..b5473e6 100644 --- a/src/InternshipSystem.Api/Program.cs +++ b/src/InternshipSystem.Api/Program.cs @@ -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(); } diff --git a/src/InternshipSystem.Api/Startup.cs b/src/InternshipSystem.Api/Startup.cs index 840b91e..e2db791 100644 --- a/src/InternshipSystem.Api/Startup.cs +++ b/src/InternshipSystem.Api/Startup.cs @@ -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();