fix(backend): add missing domain foreign keys
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Socialize.Api.Modules.ContentItems.Data;
|
||||
using Socialize.Api.Modules.Workspaces.Data;
|
||||
|
||||
namespace Socialize.Api.Modules.Approvals.Data;
|
||||
|
||||
@@ -20,6 +22,14 @@ internal static class ApprovalModelConfiguration
|
||||
workflowInstance.HasIndex(x => new { x.ContentItemId, x.State })
|
||||
.IsUnique()
|
||||
.HasFilter("\"State\" = 'Pending'");
|
||||
workflowInstance.HasOne<Workspace>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.WorkspaceId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
workflowInstance.HasOne<ContentItem>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.ContentItemId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<ApprovalRequest>(approvalRequest =>
|
||||
@@ -40,6 +50,18 @@ internal static class ApprovalModelConfiguration
|
||||
approvalRequest.HasIndex(x => x.ContentItemId);
|
||||
approvalRequest.HasIndex(x => x.WorkflowInstanceId);
|
||||
approvalRequest.HasIndex(x => x.ReviewerEmail);
|
||||
approvalRequest.HasOne<Workspace>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.WorkspaceId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
approvalRequest.HasOne<ContentItem>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.ContentItemId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
approvalRequest.HasOne<ApprovalWorkflowInstance>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.WorkflowInstanceId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<ApprovalDecision>(approvalDecision =>
|
||||
@@ -54,6 +76,10 @@ internal static class ApprovalModelConfiguration
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasDefaultValueSql("CURRENT_TIMESTAMP");
|
||||
approvalDecision.HasIndex(x => x.ApprovalRequestId);
|
||||
approvalDecision.HasOne<ApprovalRequest>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.ApprovalRequestId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<WorkspaceApprovalStepConfiguration>(approvalStep =>
|
||||
@@ -69,6 +95,10 @@ internal static class ApprovalModelConfiguration
|
||||
.HasDefaultValueSql("CURRENT_TIMESTAMP");
|
||||
approvalStep.HasIndex(x => x.WorkspaceId);
|
||||
approvalStep.HasIndex(x => new { x.WorkspaceId, x.SortOrder }).IsUnique();
|
||||
approvalStep.HasOne<Workspace>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.WorkspaceId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
|
||||
return modelBuilder;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Socialize.Api.Modules.ContentItems.Data;
|
||||
using Socialize.Api.Modules.Workspaces.Data;
|
||||
|
||||
namespace Socialize.Api.Modules.Assets.Data;
|
||||
|
||||
@@ -21,6 +23,14 @@ internal static class AssetModelConfiguration
|
||||
.HasDefaultValueSql("CURRENT_TIMESTAMP");
|
||||
asset.HasIndex(x => x.WorkspaceId);
|
||||
asset.HasIndex(x => x.ContentItemId);
|
||||
asset.HasOne<Workspace>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.WorkspaceId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
asset.HasOne<ContentItem>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.ContentItemId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<AssetRevision>(revision =>
|
||||
@@ -35,6 +45,10 @@ internal static class AssetModelConfiguration
|
||||
.HasDefaultValueSql("CURRENT_TIMESTAMP");
|
||||
revision.HasIndex(x => x.AssetId);
|
||||
revision.HasIndex(x => new { x.AssetId, x.RevisionNumber }).IsUnique();
|
||||
revision.HasOne<Asset>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.AssetId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
return modelBuilder;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Socialize.Api.Modules.Clients.Data;
|
||||
using Socialize.Api.Modules.Workspaces.Data;
|
||||
|
||||
namespace Socialize.Api.Modules.Campaigns.Data;
|
||||
|
||||
@@ -20,6 +22,14 @@ internal static class CampaignModelConfiguration
|
||||
campaign.HasIndex(x => new { x.ClientId, x.Name }).IsUnique();
|
||||
campaign.HasIndex(x => x.WorkspaceId);
|
||||
campaign.HasIndex(x => x.ClientId);
|
||||
campaign.HasOne<Workspace>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.WorkspaceId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
campaign.HasOne<Client>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.ClientId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
|
||||
return modelBuilder;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Socialize.Api.Modules.Workspaces.Data;
|
||||
|
||||
namespace Socialize.Api.Modules.Channels.Data;
|
||||
|
||||
@@ -19,6 +20,10 @@ internal static class ChannelModelConfiguration
|
||||
.HasDefaultValueSql("CURRENT_TIMESTAMP");
|
||||
channel.HasIndex(x => x.WorkspaceId);
|
||||
channel.HasIndex(x => new { x.WorkspaceId, x.Network, x.Name }).IsUnique();
|
||||
channel.HasOne<Workspace>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.WorkspaceId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
|
||||
return modelBuilder;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Socialize.Api.Modules.Workspaces.Data;
|
||||
|
||||
namespace Socialize.Api.Modules.Clients.Data;
|
||||
|
||||
@@ -21,6 +22,10 @@ internal static class ClientModelConfiguration
|
||||
.HasDefaultValueSql("CURRENT_TIMESTAMP");
|
||||
client.HasIndex(x => new { x.WorkspaceId, x.Name }).IsUnique();
|
||||
client.HasIndex(x => x.WorkspaceId);
|
||||
client.HasOne<Workspace>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.WorkspaceId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
|
||||
return modelBuilder;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Socialize.Api.Modules.ContentItems.Data;
|
||||
using Socialize.Api.Modules.Workspaces.Data;
|
||||
|
||||
namespace Socialize.Api.Modules.Comments.Data;
|
||||
|
||||
@@ -24,6 +26,18 @@ internal static class CommentModelConfiguration
|
||||
comment.HasIndex(x => x.WorkspaceId);
|
||||
comment.HasIndex(x => x.ContentItemId);
|
||||
comment.HasIndex(x => x.ParentCommentId);
|
||||
comment.HasOne<Workspace>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.WorkspaceId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
comment.HasOne<ContentItem>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.ContentItemId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
comment.HasOne<Comment>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.ParentCommentId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
|
||||
return modelBuilder;
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Socialize.Api.Modules.Campaigns.Data;
|
||||
using Socialize.Api.Modules.Clients.Data;
|
||||
using Socialize.Api.Modules.Workspaces.Data;
|
||||
|
||||
namespace Socialize.Api.Modules.ContentItems.Data;
|
||||
|
||||
@@ -22,6 +25,18 @@ internal static class ContentItemModelConfiguration
|
||||
contentItem.HasIndex(x => x.WorkspaceId);
|
||||
contentItem.HasIndex(x => x.ClientId);
|
||||
contentItem.HasIndex(x => x.CampaignId);
|
||||
contentItem.HasOne<Workspace>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.WorkspaceId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
contentItem.HasOne<Client>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.ClientId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
contentItem.HasOne<Campaign>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.CampaignId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<ContentItemRevision>(revision =>
|
||||
@@ -39,6 +54,10 @@ internal static class ContentItemModelConfiguration
|
||||
.HasDefaultValueSql("CURRENT_TIMESTAMP");
|
||||
revision.HasIndex(x => x.ContentItemId);
|
||||
revision.HasIndex(x => new { x.ContentItemId, x.RevisionNumber }).IsUnique();
|
||||
revision.HasOne<ContentItem>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.ContentItemId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<ContentItemActivityEntry>(entry =>
|
||||
@@ -56,6 +75,14 @@ internal static class ContentItemModelConfiguration
|
||||
entry.HasIndex(x => x.WorkspaceId);
|
||||
entry.HasIndex(x => x.ContentItemId);
|
||||
entry.HasIndex(x => new { x.ContentItemId, x.CreatedAt });
|
||||
entry.HasOne<Workspace>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.WorkspaceId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
entry.HasOne<ContentItem>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.ContentItemId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
|
||||
return modelBuilder;
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Socialize.Api.Modules.Campaigns.Data;
|
||||
using Socialize.Api.Modules.Clients.Data;
|
||||
using Socialize.Api.Modules.ContentItems.Data;
|
||||
using Socialize.Api.Modules.Workspaces.Data;
|
||||
|
||||
namespace Socialize.Api.Modules.Feedback.Data;
|
||||
|
||||
@@ -29,6 +33,22 @@ internal static class FeedbackModelConfiguration
|
||||
feedback.HasIndex(x => x.Type);
|
||||
feedback.HasIndex(x => x.WorkspaceId);
|
||||
feedback.HasIndex(x => x.LastActivityAt);
|
||||
feedback.HasOne<Workspace>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.WorkspaceId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
feedback.HasOne<Client>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.ClientId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
feedback.HasOne<Campaign>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.CampaignId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
feedback.HasOne<ContentItem>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.ContentItemId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<FeedbackTag>(tag =>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Socialize.Api.Modules.ContentItems.Data;
|
||||
using Socialize.Api.Modules.Workspaces.Data;
|
||||
|
||||
namespace Socialize.Api.Modules.Notifications.Data;
|
||||
|
||||
@@ -22,6 +24,14 @@ internal static class NotificationModelConfiguration
|
||||
notificationEvent.HasIndex(x => x.ContentItemId);
|
||||
notificationEvent.HasIndex(x => x.RecipientUserId);
|
||||
notificationEvent.HasIndex(x => x.CreatedAt);
|
||||
notificationEvent.HasOne<Workspace>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.WorkspaceId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
notificationEvent.HasOne<ContentItem>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.ContentItemId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
});
|
||||
|
||||
return modelBuilder;
|
||||
|
||||
@@ -41,6 +41,10 @@ internal static class WorkspaceModelConfiguration
|
||||
.HasDefaultValueSql("CURRENT_TIMESTAMP");
|
||||
workspaceInvite.HasIndex(x => x.WorkspaceId);
|
||||
workspaceInvite.HasIndex(x => new { x.WorkspaceId, x.Email, x.Status });
|
||||
workspaceInvite.HasOne<Workspace>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.WorkspaceId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
|
||||
return modelBuilder;
|
||||
|
||||
Reference in New Issue
Block a user