using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Socialize.Modules.Approvals.Data; using Socialize.Modules.Assets.Data; using Socialize.Modules.Clients.Data; using Socialize.Modules.Comments.Data; using Socialize.Modules.ContentItems.Data; using Socialize.Modules.Identity.Data; using Socialize.Modules.Notifications.Data; using Socialize.Modules.Projects.Data; using Socialize.Modules.Workspaces.Data; namespace Socialize.Data; public class AppDbContext( DbContextOptions options) : IdentityDbContext(options) { public DbSet Workspaces => Set(); public DbSet WorkspaceInvites => Set(); public DbSet Clients => Set(); public DbSet Projects => Set(); public DbSet ContentItems => Set(); public DbSet ContentItemRevisions => Set(); public DbSet Assets => Set(); public DbSet AssetRevisions => Set(); public DbSet Comments => Set(); public DbSet ApprovalRequests => Set(); public DbSet ApprovalDecisions => Set(); public DbSet NotificationEvents => Set(); protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity(workspace => { workspace.ToTable("Workspaces"); workspace.HasKey(x => x.Id); workspace.Property(x => x.Name).HasMaxLength(256).IsRequired(); workspace.Property(x => x.Slug).HasMaxLength(128).IsRequired(); workspace.Property(x => x.TimeZone).HasMaxLength(128).IsRequired(); workspace.Property(x => x.CreatedAt) .ValueGeneratedOnAdd() .HasDefaultValueSql("CURRENT_TIMESTAMP"); workspace.HasIndex(x => x.Slug).IsUnique(); workspace.HasIndex(x => x.OwnerUserId); }); modelBuilder.Entity(workspaceInvite => { workspaceInvite.ToTable("WorkspaceInvites"); workspaceInvite.HasKey(x => x.Id); workspaceInvite.Property(x => x.Email).HasMaxLength(256).IsRequired(); workspaceInvite.Property(x => x.Role).HasMaxLength(64).IsRequired(); workspaceInvite.Property(x => x.Status).HasMaxLength(64).IsRequired(); workspaceInvite.Property(x => x.CreatedAt) .ValueGeneratedOnAdd() .HasDefaultValueSql("CURRENT_TIMESTAMP"); workspaceInvite.HasIndex(x => x.WorkspaceId); workspaceInvite.HasIndex(x => new { x.WorkspaceId, x.Email, x.Status }); }); modelBuilder.Entity(client => { client.ToTable("Clients"); client.HasKey(x => x.Id); client.Property(x => x.Name).HasMaxLength(256).IsRequired(); client.Property(x => x.Status).HasMaxLength(64).IsRequired(); client.Property(x => x.PortraitUrl).HasMaxLength(2048); client.Property(x => x.PrimaryContactName).HasMaxLength(256); client.Property(x => x.PrimaryContactEmail).HasMaxLength(256); client.Property(x => x.PrimaryContactPortraitUrl).HasMaxLength(2048); client.Property(x => x.CreatedAt) .ValueGeneratedOnAdd() .HasDefaultValueSql("CURRENT_TIMESTAMP"); client.HasIndex(x => new { x.WorkspaceId, x.Name }).IsUnique(); client.HasIndex(x => x.WorkspaceId); }); modelBuilder.Entity(project => { project.ToTable("Projects"); project.HasKey(x => x.Id); project.Property(x => x.Name).HasMaxLength(256).IsRequired(); project.Property(x => x.Description).HasMaxLength(4000); project.Property(x => x.Notes).HasMaxLength(4000); project.Property(x => x.Status).HasMaxLength(64).IsRequired(); project.Property(x => x.CreatedAt) .ValueGeneratedOnAdd() .HasDefaultValueSql("CURRENT_TIMESTAMP"); project.HasIndex(x => new { x.ClientId, x.Name }).IsUnique(); project.HasIndex(x => x.WorkspaceId); project.HasIndex(x => x.ClientId); }); modelBuilder.Entity(contentItem => { contentItem.ToTable("ContentItems"); contentItem.HasKey(x => x.Id); contentItem.Property(x => x.Title).HasMaxLength(256).IsRequired(); contentItem.Property(x => x.PublicationMessage).HasMaxLength(4000).IsRequired(); contentItem.Property(x => x.PublicationTargets).HasMaxLength(512).IsRequired(); contentItem.Property(x => x.Hashtags).HasMaxLength(1024); contentItem.Property(x => x.Status).HasMaxLength(64).IsRequired(); contentItem.Property(x => x.CurrentRevisionLabel).HasMaxLength(32).IsRequired(); contentItem.Property(x => x.CreatedAt) .ValueGeneratedOnAdd() .HasDefaultValueSql("CURRENT_TIMESTAMP"); contentItem.HasIndex(x => x.WorkspaceId); contentItem.HasIndex(x => x.ClientId); contentItem.HasIndex(x => x.ProjectId); }); modelBuilder.Entity(revision => { revision.ToTable("ContentItemRevisions"); revision.HasKey(x => x.Id); revision.Property(x => x.RevisionLabel).HasMaxLength(32).IsRequired(); revision.Property(x => x.Title).HasMaxLength(256).IsRequired(); revision.Property(x => x.PublicationMessage).HasMaxLength(4000).IsRequired(); revision.Property(x => x.PublicationTargets).HasMaxLength(512).IsRequired(); revision.Property(x => x.Hashtags).HasMaxLength(1024); revision.Property(x => x.ChangeSummary).HasMaxLength(1024); revision.Property(x => x.CreatedAt) .ValueGeneratedOnAdd() .HasDefaultValueSql("CURRENT_TIMESTAMP"); revision.HasIndex(x => x.ContentItemId); revision.HasIndex(x => new { x.ContentItemId, x.RevisionNumber }).IsUnique(); }); modelBuilder.Entity(asset => { asset.ToTable("Assets"); asset.HasKey(x => x.Id); asset.Property(x => x.AssetType).HasMaxLength(64).IsRequired(); asset.Property(x => x.SourceType).HasMaxLength(64).IsRequired(); asset.Property(x => x.DisplayName).HasMaxLength(256).IsRequired(); asset.Property(x => x.GoogleDriveFileId).HasMaxLength(256); asset.Property(x => x.GoogleDriveLink).HasMaxLength(2048); asset.Property(x => x.PreviewUrl).HasMaxLength(2048); asset.Property(x => x.CreatedAt) .ValueGeneratedOnAdd() .HasDefaultValueSql("CURRENT_TIMESTAMP"); asset.HasIndex(x => x.WorkspaceId); asset.HasIndex(x => x.ContentItemId); }); modelBuilder.Entity(revision => { revision.ToTable("AssetRevisions"); revision.HasKey(x => x.Id); revision.Property(x => x.SourceReference).HasMaxLength(2048).IsRequired(); revision.Property(x => x.PreviewUrl).HasMaxLength(2048); revision.Property(x => x.Notes).HasMaxLength(1024); revision.Property(x => x.CreatedAt) .ValueGeneratedOnAdd() .HasDefaultValueSql("CURRENT_TIMESTAMP"); revision.HasIndex(x => x.AssetId); revision.HasIndex(x => new { x.AssetId, x.RevisionNumber }).IsUnique(); }); modelBuilder.Entity(comment => { comment.ToTable("Comments"); comment.HasKey(x => x.Id); comment.Property(x => x.AuthorDisplayName).HasMaxLength(256).IsRequired(); comment.Property(x => x.AuthorEmail).HasMaxLength(256).IsRequired(); comment.Property(x => x.Body).HasMaxLength(4000).IsRequired(); comment.Property(x => x.CreatedAt) .ValueGeneratedOnAdd() .HasDefaultValueSql("CURRENT_TIMESTAMP"); comment.HasIndex(x => x.WorkspaceId); comment.HasIndex(x => x.ContentItemId); comment.HasIndex(x => x.ParentCommentId); }); modelBuilder.Entity(approvalRequest => { approvalRequest.ToTable("ApprovalRequests"); approvalRequest.HasKey(x => x.Id); approvalRequest.Property(x => x.Stage).HasMaxLength(64).IsRequired(); approvalRequest.Property(x => x.ReviewerName).HasMaxLength(256).IsRequired(); approvalRequest.Property(x => x.ReviewerEmail).HasMaxLength(256).IsRequired(); approvalRequest.Property(x => x.State).HasMaxLength(64).IsRequired(); approvalRequest.Property(x => x.AccessToken).HasMaxLength(64).IsRequired(); approvalRequest.Property(x => x.SentAt) .ValueGeneratedOnAdd() .HasDefaultValueSql("CURRENT_TIMESTAMP"); approvalRequest.HasIndex(x => x.WorkspaceId); approvalRequest.HasIndex(x => x.ContentItemId); approvalRequest.HasIndex(x => x.ReviewerEmail); }); modelBuilder.Entity(approvalDecision => { approvalDecision.ToTable("ApprovalDecisions"); approvalDecision.HasKey(x => x.Id); approvalDecision.Property(x => x.Decision).HasMaxLength(64).IsRequired(); approvalDecision.Property(x => x.Comment).HasMaxLength(2048); approvalDecision.Property(x => x.DecidedByName).HasMaxLength(256).IsRequired(); approvalDecision.Property(x => x.DecidedByEmail).HasMaxLength(256).IsRequired(); approvalDecision.Property(x => x.CreatedAt) .ValueGeneratedOnAdd() .HasDefaultValueSql("CURRENT_TIMESTAMP"); approvalDecision.HasIndex(x => x.ApprovalRequestId); }); modelBuilder.Entity(notificationEvent => { notificationEvent.ToTable("NotificationEvents"); notificationEvent.HasKey(x => x.Id); notificationEvent.Property(x => x.EventType).HasMaxLength(128).IsRequired(); notificationEvent.Property(x => x.EntityType).HasMaxLength(128).IsRequired(); notificationEvent.Property(x => x.Message).HasMaxLength(1024).IsRequired(); notificationEvent.Property(x => x.RecipientEmail).HasMaxLength(256); notificationEvent.Property(x => x.MetadataJson).HasMaxLength(4000); notificationEvent.Property(x => x.CreatedAt) .ValueGeneratedOnAdd() .HasDefaultValueSql("CURRENT_TIMESTAMP"); notificationEvent.HasIndex(x => x.WorkspaceId); notificationEvent.HasIndex(x => x.ContentItemId); notificationEvent.HasIndex(x => x.RecipientUserId); notificationEvent.HasIndex(x => x.CreatedAt); }); } }