[CHANGE] Preparing database

This commit is contained in:
max
2025-08-11 00:44:52 +02:00
parent 9edd0690cf
commit 3c3f2db4e7
6 changed files with 73 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
using Manager.Data.Models.ApplicationContext;
using Microsoft.EntityFrameworkCore;
namespace Manager.Data.Contexts;
public sealed class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
ChangeTracker.LazyLoadingEnabled = false;
}
public DbSet<SettingsGroupModel> SettingsGroups { get; set; }
public DbSet<SettingsModel> Settings { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<SettingsGroupModel>(sg =>
{
sg.ToTable("settings_groups");
sg.HasKey(x => x.Id);
});
modelBuilder.Entity<SettingsModel>(settingsEntity =>
{
settingsEntity.ToTable("settings");
settingsEntity.HasKey(x => x.Key);
});
base.OnModelCreating(modelBuilder);
}
}

View File

@@ -0,0 +1,11 @@
using Microsoft.EntityFrameworkCore;
namespace Manager.Data.Contexts;
public class LibraryDbContext : DbContext
{
public LibraryDbContext(DbContextOptions<LibraryDbContext> options) : base(options)
{
}
}

View File

@@ -0,0 +1,2 @@
namespace Manager.Data;

View File

@@ -10,4 +10,14 @@
<ProjectReference Include="..\Manager.Shared\Manager.Shared.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.8" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
<Folder Include="Models\LibraryContext\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,7 @@
namespace Manager.Data.Models.ApplicationContext;
public record SettingsGroupModel
{
public required Guid Id { get; set; }
public required string Name { get; set; }
}

View File

@@ -0,0 +1,12 @@
namespace Manager.Data.Models.ApplicationContext;
public class SettingsModel
{
public required string Key { get; set; }
public required string Name { get; set; }
public required string Description { get; set; }
public Guid? GroupId { get; set; }
public string ValueType { get; set; } = nameof(String);
public object? Value { get; set; }
public object? DefaultValue { get; set; }
}