diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2023-01-13 21:40:32 +0100 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2023-01-13 21:40:32 +0100 |
| commit | eb774d6781414067719e3a5e63d95dff30a464f7 (patch) | |
| tree | 8345e93791f01d1f4702d4f5e8cc586a9a078140 | |
| parent | 1b30781b484a84fc04188c67cd4890612f10bbb4 (diff) | |
| download | blob-bin-eb774d6781414067719e3a5e63d95dff30a464f7.tar.xz blob-bin-eb774d6781414067719e3a5e63d95dff30a464f7.zip | |
feat: Autocreated sqlite file
| -rw-r--r-- | src/DB.cs | 17 | ||||
| -rw-r--r-- | src/Program.cs | 3 |
2 files changed, 16 insertions, 4 deletions
@@ -2,12 +2,25 @@ using Microsoft.EntityFrameworkCore; namespace BlobBin; -public class DB : DbContext +public sealed class DB : DbContext { - public DB(DbContextOptions<DB> options) : base(options) { } + private bool _created; + + public DB(DbContextOptions<DB> options) : base(options) { + if (!_created) { + _created = true; + Database.EnsureDeleted(); + Database.EnsureCreated(); + } + } public DbSet<File> Files { get; set; } public DbSet<Paste> Pastes { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { + optionsBuilder.UseSqlite("data source = main.db"); + base.OnConfiguring(optionsBuilder); + } } public class UploadEntityBase diff --git a/src/Program.cs b/src/Program.cs index 01ca76b..89a8e02 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -1,10 +1,9 @@ global using BlobBin; using IOL.Helpers; -using Microsoft.EntityFrameworkCore; using File = BlobBin.File; var builder = WebApplication.CreateBuilder(args); -builder.Services.AddDbContext<DB>(opt => opt.UseSqlite("data source=main.db")); +builder.Services.AddDbContext<DB>(); var app = builder.Build(); app.UseFileServer(); |
