Files
tnsu-approval-route/backend/Tnsu.ApprovalRoute.Infrastructure/Persistence/ApprovalRouteDbContext.cs
T
gorbenko.pavel ba48ed1a0e
Tests / frontend-test (push) Successful in 47s
Tests / backend-test (push) Successful in 2m12s
Несколько условий шага, объединяемых через И/ИЛИ (#16)
<html>
<body>
<!--StartFragment-->
GetEmployeeByEmailAsync возвращает массив; новый HeadType.CompanyDirectors
--

<!--EndFragment-->
</body>
</html>[GetEmployeeByEmailAsync возвращает массив; новый HeadType.CompanyDirectors](http://git.tnsu.kz/gorbenko.pavel/tnsu-approval-route/commit/572749b4d7cc11bc8e1ef4184a93f18a14b710ab)

---------

Co-authored-by: gorbenko.pavel <gorbenko.pavel@tansu.kz>
Reviewed-on: http://git.tnsu.kz/gorbenko.pavel/tnsu-approval-route/pulls/16
2026-08-25 07:04:44 +00:00

81 lines
4.1 KiB
C#

using Microsoft.EntityFrameworkCore;
using Tnsu.ApprovalRoute.Domain.Entities;
using Tnsu.ApprovalRoute.Infrastructure.Persistence.Entities;
namespace Tnsu.ApprovalRoute.Infrastructure.Persistence;
public class ApprovalRouteDbContext(DbContextOptions<ApprovalRouteDbContext> options) : DbContext(options)
{
public DbSet<RequestType> RequestTypes => Set<RequestType>();
public DbSet<RequestListPartition> RequestListPartitions => Set<RequestListPartition>();
public DbSet<TemplateRoute> TemplateRoutes => Set<TemplateRoute>();
public DbSet<TemplateRouteStep> TemplateRouteSteps => Set<TemplateRouteStep>();
public DbSet<TemplateRouteStepCondition> TemplateRouteStepConditions => Set<TemplateRouteStepCondition>();
public DbSet<AppSetting> Settings => Set<AppSetting>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<AppSetting>(e =>
{
// Имя таблицы задано явно: соглашение по именам сделало бы из
// AppSetting «app_settings», а таблица должна называться так же, как
// в api-tnsu-portal, — settings.
e.ToTable("settings");
e.HasKey(x => x.OptionName);
e.Property(x => x.OptionName).HasMaxLength(128);
});
modelBuilder.Entity<RequestType>(e =>
{
e.HasKey(x => x.Id);
e.Property(x => x.Name).HasMaxLength(256).IsRequired();
e.Property(x => x.PageUrl).HasMaxLength(512).IsRequired();
e.Property(x => x.ListId).HasMaxLength(512);
e.Property(x => x.SiteUrl).HasMaxLength(512);
e.Property(x => x.Section).HasMaxLength(256).IsRequired();
});
modelBuilder.Entity<RequestListPartition>(e =>
{
e.HasKey(x => x.Id);
e.Property(x => x.ListId).HasMaxLength(512).IsRequired();
e.Property(x => x.Title).HasMaxLength(512);
e.HasOne(x => x.RequestType).WithMany(x => x.ListPartitions).HasForeignKey(x => x.RequestTypeId);
// Номер уникален в пределах типа заявок — вторая попытка записать тот же
// номер (например, при двойном запуске задачи) упадёт на этом индексе,
// а не создаст в реестре дубль.
e.HasIndex(x => new { x.RequestTypeId, x.Number }).IsUnique();
});
modelBuilder.Entity<TemplateRoute>(e =>
{
e.HasKey(x => x.Id);
e.HasOne(x => x.RequestType).WithMany(x => x.Routes).HasForeignKey(x => x.RequestTypeId);
e.HasIndex(x => new { x.RequestTypeId, x.DepartmentId, x.CompanyId, x.ByProject }).IsUnique();
});
modelBuilder.Entity<TemplateRouteStep>(e =>
{
e.HasKey(x => x.Id);
e.Property(x => x.ExecutorEmail).HasMaxLength(256);
e.Property(x => x.Position).HasMaxLength(128);
e.Property(x => x.ProjectRole).HasConversion<string>().HasMaxLength(32);
e.Property(x => x.HeadType).HasConversion<string>().HasMaxLength(32);
e.Property(x => x.Status).HasConversion<string>().HasMaxLength(32).IsRequired();
e.Property(x => x.ConditionsLogic).HasConversion<string>().HasMaxLength(16).IsRequired();
e.HasOne(x => x.Route).WithMany(x => x.Steps).HasForeignKey(x => x.RouteId);
e.HasIndex(x => new { x.RouteId, x.OrderNo });
});
modelBuilder.Entity<TemplateRouteStepCondition>(e =>
{
e.HasKey(x => x.Id);
e.Property(x => x.FieldName).HasMaxLength(128).IsRequired();
e.Property(x => x.Operation).HasConversion<string>().HasMaxLength(32).IsRequired();
e.Property(x => x.Value).HasMaxLength(256).IsRequired();
e.HasOne(x => x.Step).WithMany(x => x.Conditions).HasForeignKey(x => x.StepId).OnDelete(DeleteBehavior.Cascade);
e.HasIndex(x => new { x.StepId, x.OrderNo });
});
}
}