feat(db): map TemplateFolder entity and Template.FolderId
This commit is contained in:
@@ -26,6 +26,12 @@ public class TemplateConfiguration : IEntityTypeConfiguration<Template>
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired(false);
|
||||
|
||||
builder.HasOne<TemplateFolder>()
|
||||
.WithMany()
|
||||
.HasForeignKey(t => t.FolderId)
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired(false);
|
||||
|
||||
builder.HasMany(t => t.Attributes)
|
||||
.WithOne()
|
||||
.HasForeignKey(a => a.TemplateId)
|
||||
@@ -147,3 +153,24 @@ public class TemplateCompositionConfiguration : IEntityTypeConfiguration<Templat
|
||||
builder.HasIndex(c => new { c.TemplateId, c.InstanceName }).IsUnique();
|
||||
}
|
||||
}
|
||||
|
||||
public class TemplateFolderConfiguration : IEntityTypeConfiguration<TemplateFolder>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<TemplateFolder> builder)
|
||||
{
|
||||
builder.HasKey(f => f.Id);
|
||||
|
||||
builder.Property(f => f.Name)
|
||||
.IsRequired()
|
||||
.HasMaxLength(200);
|
||||
|
||||
builder.HasOne<TemplateFolder>()
|
||||
.WithMany()
|
||||
.HasForeignKey(f => f.ParentFolderId)
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired(false);
|
||||
|
||||
// Unique sibling name (case-insensitive enforced at service layer; this index is for fast lookup)
|
||||
builder.HasIndex(f => new { f.ParentFolderId, f.Name }).IsUnique();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user