Auto migration next vesrion
This commit is contained in:
parent
1443abc391
commit
12e952b0ce
@ -1,4 +1,3 @@
|
|||||||
using System.Threading.Tasks;
|
|
||||||
using InternshipSystem.Repository;
|
using InternshipSystem.Repository;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using InternshipSystem.Repository;
|
using System;
|
||||||
|
using InternshipSystem.Repository;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Internal;
|
using Microsoft.EntityFrameworkCore.Internal;
|
||||||
@ -10,11 +11,24 @@ namespace InternshipSystem.Api.Extensions
|
|||||||
{
|
{
|
||||||
public static IApplicationBuilder UseMigration(this IApplicationBuilder app)
|
public static IApplicationBuilder UseMigration(this IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
using var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope();
|
bool done = false;
|
||||||
using var context = serviceScope.ServiceProvider.GetService<InternshipPractiseSupervisorDbContext>();
|
while (!done)
|
||||||
|
{
|
||||||
context.Database.Migrate();
|
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;
|
return app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
using Serilog.Formatting.Compact;
|
|
||||||
|
|
||||||
namespace InternshipSystem.Api
|
namespace InternshipSystem.Api
|
||||||
{
|
{
|
||||||
@ -17,8 +9,6 @@ namespace InternshipSystem.Api
|
|||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
//TODO: remove ugly solution for to early migration error on startup
|
|
||||||
Thread.Sleep(10000);
|
|
||||||
CreateHostBuilder(args).Build().Run();
|
CreateHostBuilder(args).Build().Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using InternshipSystem.Api.Controllers;
|
using InternshipSystem.Api.Controllers;
|
||||||
using InternshipSystem.Api.Extensions;
|
using InternshipSystem.Api.Extensions;
|
||||||
@ -11,7 +8,6 @@ using InternshipSystem.Api.ModelBinders;
|
|||||||
using InternshipSystem.Api.Options;
|
using InternshipSystem.Api.Options;
|
||||||
using InternshipSystem.Api.Security;
|
using InternshipSystem.Api.Security;
|
||||||
using InternshipSystem.Api.Services;
|
using InternshipSystem.Api.Services;
|
||||||
using InternshipSystem.Core;
|
|
||||||
using InternshipSystem.Repository;
|
using InternshipSystem.Repository;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
@ -64,7 +60,7 @@ namespace InternshipSystem.Api
|
|||||||
.AddControllers(o => { o.ModelBinderProviders.Insert(0, new UserBinderProvider()); });
|
.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();
|
app.UseMigration();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user