You've already forked onecmonitor
mirror of
https://github.com/akpaevj/onecmonitor.git
synced 2026-06-19 22:59:58 +02:00
55 lines
2.0 KiB
C#
55 lines
2.0 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using OnecMonitor.Server.Converters.Sqlite;
|
|
using OnecMonitor.Server.Models;
|
|
using OnecMonitor.Common.DTO;
|
|
|
|
namespace OnecMonitor.Server
|
|
{
|
|
public class AppDbContext : DbContext
|
|
{
|
|
public string DbPath { get; }
|
|
|
|
public DbSet<Agent> Agents { get; set; }
|
|
public DbSet<LogTemplate> LogTemplates { get; set; }
|
|
public DbSet<TechLogSeance> TechLogSeances { get; set; }
|
|
public DbSet<TechLogFilter> TechLogFilters { get; set; }
|
|
public DbSet<V8Configuration> Configurations { get; set; }
|
|
public DbSet<Credentials> Credentials { get; set; }
|
|
public DbSet<InfoBase> InfoBases { get; set; }
|
|
public DbSet<Cluster> Clusters { get; set; }
|
|
public DbSet<UpdateInfoBaseTask> UpdateInfoBaseTasks { get; set; }
|
|
public DbSet<UpdateInfoBaseTaskResult> UpdateInfoBaseTaskResults { get; set; }
|
|
|
|
public AppDbContext(IHostEnvironment hostEnvironment)
|
|
=> DbPath = Path.Join(hostEnvironment.ContentRootPath, "om-server.db");
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
optionsBuilder.UseSqlite($"Data Source={DbPath}");
|
|
}
|
|
|
|
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
|
|
{
|
|
configurationBuilder.Properties<Guid>()
|
|
.HaveConversion<GuidStringConverter>();
|
|
|
|
configurationBuilder.Properties<DateTime>()
|
|
.HaveConversion<DateTimeStringConverter>();
|
|
}
|
|
|
|
public static void AddBuiltInLogTemplate(MigrationBuilder migrationBuilder, Guid id, string name, string content)
|
|
{
|
|
migrationBuilder.Sql(
|
|
$"""
|
|
INSERT INTO LogTemplates
|
|
VALUES (
|
|
'{id}',
|
|
'{name}',
|
|
'{content}'
|
|
)
|
|
""");
|
|
}
|
|
}
|
|
}
|