63 lines
2.0 KiB
C#
63 lines
2.0 KiB
C#
|
|
using Microsoft.EntityFrameworkCore;
|
|||
|
|
using TriliumMind.Data.Entities;
|
|||
|
|
using TriliumMind.Models;
|
|||
|
|
|
|||
|
|
namespace TriliumMind.Data;
|
|||
|
|
|
|||
|
|
public class SqliteDbContext : DbContext, IAppDbContext
|
|||
|
|
{
|
|||
|
|
private readonly string _dbFilePath;
|
|||
|
|
|
|||
|
|
public DbSet<Config> Configs { get; set; }
|
|||
|
|
public DbSet<JiraIssue> JiraIssues { get; set; }
|
|||
|
|
|
|||
|
|
public SqliteDbContext(AppConfigs configs)
|
|||
|
|
{
|
|||
|
|
var dbPath = configs.AppSettings.Database.Sqlite.DatabaseFilePath;
|
|||
|
|
|
|||
|
|
if (Path.IsPathRooted(dbPath) && File.Exists(dbPath))
|
|||
|
|
{
|
|||
|
|
_dbFilePath = dbPath;
|
|||
|
|
}
|
|||
|
|
else if (Path.IsPathRooted(dbPath))
|
|||
|
|
{
|
|||
|
|
_dbFilePath = dbPath;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
var basePath = AppContext.BaseDirectory;
|
|||
|
|
_dbFilePath = Path.Combine(basePath, dbPath);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|||
|
|
=> optionsBuilder.UseSqlite($"Data Source={_dbFilePath}");
|
|||
|
|
|
|||
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|||
|
|
{
|
|||
|
|
base.OnModelCreating(modelBuilder);
|
|||
|
|
|
|||
|
|
modelBuilder.Entity<Config>(entity =>
|
|||
|
|
{
|
|||
|
|
entity.HasKey(e => e.Key);
|
|||
|
|
entity.Property(e => e.Key).IsRequired();
|
|||
|
|
entity.Property(e => e.Value).IsRequired();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
modelBuilder.Entity<JiraIssue>(entity =>
|
|||
|
|
{
|
|||
|
|
entity.HasKey(e => e.Key);
|
|||
|
|
entity.Property(e => e.Key).IsRequired();
|
|||
|
|
entity.Property(e => e.Summary).IsRequired();
|
|||
|
|
entity.Property(e => e.Type).IsRequired();
|
|||
|
|
entity.Property(e => e.Status).IsRequired();
|
|||
|
|
entity.Property(e => e.Assignee).IsRequired();
|
|||
|
|
entity.Property(e => e.Manager).IsRequired();
|
|||
|
|
entity.Property(e => e.Due).IsRequired();
|
|||
|
|
entity.Property(e => e.Updated).IsRequired();
|
|||
|
|
entity.Property(e => e.Published).IsRequired();
|
|||
|
|
entity.Property(e => e.NeedNotify).IsRequired();
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|