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 /src/DB.cs | |
| parent | 1b30781b484a84fc04188c67cd4890612f10bbb4 (diff) | |
| download | blob-bin-eb774d6781414067719e3a5e63d95dff30a464f7.tar.xz blob-bin-eb774d6781414067719e3a5e63d95dff30a464f7.zip | |
feat: Autocreated sqlite file
Diffstat (limited to 'src/DB.cs')
| -rw-r--r-- | src/DB.cs | 17 |
1 files changed, 15 insertions, 2 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 |
