feat: add organization domain foundation
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Socialize.Api.Modules.Organizations.Data;
|
||||
|
||||
public static class OrganizationModelConfiguration
|
||||
{
|
||||
public static ModelBuilder ConfigureOrganizationsModule(this ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Organization>(organization =>
|
||||
{
|
||||
organization.ToTable("Organizations");
|
||||
organization.HasKey(x => x.Id);
|
||||
organization.Property(x => x.Name).HasMaxLength(256).IsRequired();
|
||||
organization.Property(x => x.Slug).HasMaxLength(128).IsRequired();
|
||||
organization.Property(x => x.CreatedAt)
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasDefaultValueSql("CURRENT_TIMESTAMP");
|
||||
organization.HasIndex(x => x.Slug).IsUnique();
|
||||
organization.HasIndex(x => x.OwnerUserId);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<OrganizationMembership>(membership =>
|
||||
{
|
||||
membership.ToTable("OrganizationMemberships");
|
||||
membership.HasKey(x => x.Id);
|
||||
membership.Property(x => x.Role).HasMaxLength(64).IsRequired();
|
||||
membership.Property(x => x.CreatedAt)
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasDefaultValueSql("CURRENT_TIMESTAMP");
|
||||
membership.HasIndex(x => x.OrganizationId);
|
||||
membership.HasIndex(x => x.UserId);
|
||||
membership.HasIndex(x => new { x.OrganizationId, x.UserId }).IsUnique();
|
||||
membership.HasOne<Organization>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.OrganizationId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
return modelBuilder;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user