Updated Program
Updated Program to have SQLite Configuration done through Connection Strings. Added auto migration for the database, if we get an exception, we create the database instead (As it doesn't exist.)
This commit is contained in:
parent
2746bd84ed
commit
0359732385
1 changed files with 16 additions and 1 deletions
|
|
@ -1,13 +1,15 @@
|
|||
using FreeTubeSync;
|
||||
using FreeTubeSync.Database;
|
||||
using FreeTubeSync.EndPoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
builder.Services.AddDbContext<DataContext>();
|
||||
builder.Services.AddDbContext<DataContext>(options =>
|
||||
options.UseSqlite(builder.Configuration.GetConnectionString("FreeTubeSync")));
|
||||
|
||||
builder.Services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
|
||||
|
||||
|
|
@ -21,4 +23,17 @@ app.MapProfileEndpoints();
|
|||
app.MapSearchHistoryEndpoints();
|
||||
app.MapSettingEndpoints();
|
||||
|
||||
await using(var serviceScope = app.Services.CreateAsyncScope())
|
||||
await using (var dbContext = serviceScope.ServiceProvider.GetRequiredService<DataContext>())
|
||||
{
|
||||
try
|
||||
{
|
||||
await dbContext.Database.MigrateAsync();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await dbContext.Database.EnsureCreatedAsync();
|
||||
}
|
||||
}
|
||||
|
||||
app.Run();
|
||||
Loading…
Add table
Add a link
Reference in a new issue