| | | 1 | | using ArturRios.Heimdall.Domain.Entities; |
| | | 2 | | using Microsoft.EntityFrameworkCore; |
| | | 3 | | using Microsoft.EntityFrameworkCore.Metadata.Builders; |
| | | 4 | | |
| | | 5 | | namespace ArturRios.Heimdall.Data.EntityMaps; |
| | | 6 | | |
| | | 7 | | internal static class ScopePermissionDbMap |
| | | 8 | | { |
| | | 9 | | public static void Configure(this EntityTypeBuilder<ScopePermission> scopePermission) |
| | | 10 | | { |
| | 3 | 11 | | scopePermission.ToTable("scope_permission"); |
| | | 12 | | |
| | 3 | 13 | | scopePermission.HasKey(x => x.Id); |
| | | 14 | | |
| | 3 | 15 | | scopePermission.Property(x => x.PublicId).IsRequired(); |
| | 3 | 16 | | scopePermission.HasIndex(x => x.PublicId).IsUnique(); |
| | | 17 | | |
| | 3 | 18 | | scopePermission.Property(x => x.Name).IsRequired(); |
| | | 19 | | |
| | 3 | 20 | | scopePermission.Property(x => x.Description); |
| | | 21 | | |
| | 3 | 22 | | scopePermission.Property(x => x.IncludeAsJwtClaim).HasDefaultValue(false); |
| | 3 | 23 | | scopePermission.Property(x => x.IsDeleted).HasDefaultValue(false); |
| | | 24 | | |
| | 3 | 25 | | scopePermission.Property(x => x.CreatedAt).HasDefaultValueSql("now()"); |
| | 3 | 26 | | scopePermission.Property(x => x.UpdatedAt).HasDefaultValueSql("now()"); |
| | | 27 | | |
| | | 28 | | // A permission belongs to exactly one scope; hard-deleting the scope cascades to its |
| | | 29 | | // permissions. |
| | 3 | 30 | | scopePermission.HasOne(x => x.Scope) |
| | 3 | 31 | | .WithMany(s => s.ScopePermissions) |
| | 3 | 32 | | .HasForeignKey(x => x.ScopeId) |
| | 3 | 33 | | .IsRequired() |
| | 3 | 34 | | .OnDelete(DeleteBehavior.Cascade); |
| | 3 | 35 | | } |
| | | 36 | | } |