602554ac64
Tests / test (push) Successful in 5m45s
Co-authored-by: gorbenko.pavel <gorbenko.pavel@tansu.kz> Reviewed-on: http://git.tnsu.kz/gorbenko.pavel/tnsu-approval-route/pulls/2 Co-authored-by: gorbenko.pavel <gorbenko.pavel@tnsu.kz> Co-committed-by: gorbenko.pavel <gorbenko.pavel@tnsu.kz>
42 lines
1.8 KiB
C#
42 lines
1.8 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Tnsu.ApprovalRoute.Domain.Entities;
|
|
|
|
namespace Tnsu.ApprovalRoute.Infrastructure.Persistence;
|
|
|
|
public class ApprovalRouteDbContext(DbContextOptions<ApprovalRouteDbContext> options) : DbContext(options)
|
|
{
|
|
public DbSet<RequestType> RequestTypes => Set<RequestType>();
|
|
public DbSet<TemplateRoute> TemplateRoutes => Set<TemplateRoute>();
|
|
public DbSet<TemplateRouteStep> TemplateRouteSteps => Set<TemplateRouteStep>();
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
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();
|
|
});
|
|
|
|
modelBuilder.Entity<TemplateRoute>(e =>
|
|
{
|
|
e.HasKey(x => x.Id);
|
|
e.Property(x => x.RouteType).HasConversion<string>().HasMaxLength(32).IsRequired();
|
|
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.HasOne(x => x.Route).WithMany(x => x.Steps).HasForeignKey(x => x.RouteId);
|
|
e.HasIndex(x => new { x.RouteId, x.OrderNo });
|
|
});
|
|
}
|
|
}
|