| | | 1 | | using Syki.Back.Domain.Identity; |
| | | 2 | | using Syki.Back.Domain.Institutions; |
| | | 3 | | |
| | | 4 | | namespace Syki.Back.Database.Identity; |
| | | 5 | | |
| | | 6 | | public class SykiRoleDbConfig : IEntityTypeConfiguration<SykiRole> |
| | | 7 | | { |
| | | 8 | | public void Configure(EntityTypeBuilder<SykiRole> entity) |
| | | 9 | | { |
| | 4 | 10 | | entity.ToTable("roles", DbSchemas.Syki); |
| | | 11 | | |
| | 4 | 12 | | entity.HasKey(e => e.Id); |
| | | 13 | | |
| | 4 | 14 | | entity.Property(e => e.Description) |
| | 4 | 15 | | .IsRequired(); |
| | | 16 | | |
| | 4 | 17 | | entity.Property(e => e.Permissions) |
| | 4 | 18 | | .HasColumnType("integer[]") |
| | 4 | 19 | | .IsRequired(); |
| | | 20 | | |
| | 4 | 21 | | entity.HasOne<Institution>() |
| | 4 | 22 | | .WithMany() |
| | 4 | 23 | | .HasPrincipalKey(u => u.Id) |
| | 4 | 24 | | .HasForeignKey(e => e.OwnerId); |
| | | 25 | | |
| | | 26 | | // Remove o índice único padrão do ASP.NET Identity |
| | 4 | 27 | | entity.HasIndex(e => e.NormalizedName) |
| | 4 | 28 | | .IsUnique(false) |
| | 4 | 29 | | .HasDatabaseName("role_name_index"); |
| | | 30 | | |
| | | 31 | | // Índice único composto: permite mesmo nome em orgs diferentes |
| | | 32 | | // AreNullsDistinct(false) gera NULLS NOT DISTINCT no PostgreSQL 15+ |
| | 4 | 33 | | entity.HasIndex(e => new { e.OwnerId, e.NormalizedName }) |
| | 4 | 34 | | .IsUnique() |
| | 4 | 35 | | .AreNullsDistinct(false); |
| | 4 | 36 | | } |
| | | 37 | | } |