| | | 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 RoleDbMap |
| | | 8 | | { |
| | | 9 | | public static void Configure(this EntityTypeBuilder<Role> role) |
| | | 10 | | { |
| | 3 | 11 | | role.ToTable("role"); |
| | | 12 | | |
| | 3 | 13 | | role.HasKey(x => x.Id); |
| | | 14 | | |
| | | 15 | | // Role ids are assigned from the Roles enum by DatabaseSeeder (SystemAdmin = 1, |
| | | 16 | | // ScopeAdmin = 2, User = 3), not generated by the database. Roles are fixed reference data |
| | | 17 | | // (FR-RO-01), so there is no identity sequence left to drift out of step with the rows. |
| | 3 | 18 | | role.Property(x => x.Id).ValueGeneratedNever(); |
| | | 19 | | |
| | 3 | 20 | | role.Property(x => x.PublicId).IsRequired(); |
| | 3 | 21 | | role.HasIndex(x => x.PublicId).IsUnique(); |
| | | 22 | | |
| | 3 | 23 | | role.Property(x => x.Name).IsRequired(); |
| | | 24 | | |
| | | 25 | | // Role name is unique — User | ScopeAdmin | SystemAdmin (§4.3). |
| | 3 | 26 | | role.HasIndex(x => x.Name).IsUnique(); |
| | | 27 | | |
| | | 28 | | // The Person -> Role relationship is configured in PersonDbMap. |
| | 3 | 29 | | } |
| | | 30 | | } |