From 03afb20472df5ac53c7651aa690f8b59f5a318d1 Mon Sep 17 00:00:00 2001 From: Scott Kirkland Date: Mon, 6 Nov 2023 15:09:20 -0800 Subject: [PATCH] limit value and create a covering index --- Sloth.Core/Domain/TransactionMetadata.cs | 6 +- .../20231106230628_MetadataIndex.Designer.cs | 1268 +++++++++++++++++ .../20231106230628_MetadataIndex.cs | 40 + .../Migrations/SlothDbContextModelSnapshot.cs | 4 +- Sloth.Core/SlothDbContext.cs | 1 + 5 files changed, 1316 insertions(+), 3 deletions(-) create mode 100644 Sloth.Core/Migrations/20231106230628_MetadataIndex.Designer.cs create mode 100644 Sloth.Core/Migrations/20231106230628_MetadataIndex.cs diff --git a/Sloth.Core/Domain/TransactionMetadata.cs b/Sloth.Core/Domain/TransactionMetadata.cs index acb7ab77..0d0b02bf 100644 --- a/Sloth.Core/Domain/TransactionMetadata.cs +++ b/Sloth.Core/Domain/TransactionMetadata.cs @@ -21,6 +21,7 @@ public class TransactionMetadata public string Name { get; set; } [Required] + [MaxLength(450)] public string Value { get; set; } public static void OnModelCreating(ModelBuilder modelBuilder) @@ -28,8 +29,9 @@ public static void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity() .HasIndex(r => r.TransactionId); - // modelBuilder.Entity() - // .HasIndex(r => r.Name); + // create a covering index for key and value + modelBuilder.Entity() + .HasIndex(r => new { r.TransactionId, r.Name, r.Value }); } } } diff --git a/Sloth.Core/Migrations/20231106230628_MetadataIndex.Designer.cs b/Sloth.Core/Migrations/20231106230628_MetadataIndex.Designer.cs new file mode 100644 index 00000000..8513d4a7 --- /dev/null +++ b/Sloth.Core/Migrations/20231106230628_MetadataIndex.Designer.cs @@ -0,0 +1,1268 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Sloth.Core; + +#nullable disable + +namespace Sloth.Core.Migrations +{ + [DbContext(typeof(SlothDbContext))] + [Migration("20231106230628_MetadataIndex")] + partial class MetadataIndex + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + modelBuilder.HasSequence("Document_Number_Seq") + .HasMin(1L) + .HasMax(999999999L) + .IsCyclic(); + + modelBuilder.HasSequence("KFS_Tracking_Number_Seq") + .HasMin(1L) + .HasMax(9999999999L) + .IsCyclic(); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("Sloth.Core.Models.ApiKey", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("Issued") + .HasColumnType("datetime2"); + + b.Property("Key") + .HasColumnType("nvarchar(450)"); + + b.Property("Revoked") + .HasColumnType("datetime2"); + + b.Property("TeamId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("Key") + .IsUnique() + .HasFilter("[Key] IS NOT NULL"); + + b.HasIndex("TeamId"); + + b.ToTable("ApiKeys", (string)null); + }); + + modelBuilder.Entity("Sloth.Core.Models.Blob", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("Container") + .HasColumnType("nvarchar(max)"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("FileName") + .HasColumnType("nvarchar(450)"); + + b.Property("MediaType") + .HasColumnType("nvarchar(max)"); + + b.Property("UploadedDate") + .HasColumnType("datetime2"); + + b.Property("Uri") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("FileName"); + + b.HasIndex("UploadedDate"); + + b.HasIndex("Uri"); + + b.ToTable("Blobs"); + }); + + modelBuilder.Entity("Sloth.Core.Models.Integration", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ClearingAccount") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("HoldingAccount") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("MerchantId") + .HasColumnType("nvarchar(max)"); + + b.Property("ReportPasswordKey") + .HasColumnType("nvarchar(max)"); + + b.Property("ReportUsername") + .HasColumnType("nvarchar(max)"); + + b.Property("SourceId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("TeamId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Type") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("SourceId"); + + b.HasIndex("TeamId"); + + b.ToTable("Integrations"); + }); + + modelBuilder.Entity("Sloth.Core.Models.JobRecord", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("Details") + .HasColumnType("nvarchar(max)"); + + b.Property("EndedAt") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("ProcessedDate") + .HasColumnType("datetime2"); + + b.Property("StartedAt") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasMaxLength(32) + .HasColumnType("nvarchar(32)"); + + b.Property("TotalTransactions") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("EndedAt"); + + b.HasIndex("Name"); + + b.HasIndex("ProcessedDate"); + + b.HasIndex("StartedAt"); + + b.HasIndex("Status"); + + b.ToTable("JobRecords"); + }); + + modelBuilder.Entity("Sloth.Core.Models.JournalRequest", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("RequestId") + .HasColumnType("uniqueidentifier"); + + b.Property("SourceId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Status") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("SourceId"); + + b.ToTable("JournalRequests"); + }); + + modelBuilder.Entity("Sloth.Core.Models.LogMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CorrelationId") + .HasColumnType("nvarchar(450)"); + + b.Property("Exception") + .HasColumnType("nvarchar(max)"); + + b.Property("JobId") + .HasColumnType("nvarchar(450)"); + + b.Property("JobName") + .HasColumnType("nvarchar(450)"); + + b.Property("Level") + .HasColumnType("nvarchar(max)"); + + b.Property("LogEvent") + .HasColumnType("nvarchar(max)"); + + b.Property("Message") + .HasColumnType("nvarchar(max)"); + + b.Property("MessageTemplate") + .HasColumnType("nvarchar(max)"); + + b.Property("Properties") + .HasColumnType("xml"); + + b.Property("Source") + .HasColumnType("nvarchar(450)"); + + b.Property("TimeStamp") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.HasIndex("CorrelationId"); + + b.HasIndex("Source"); + + b.HasIndex("JobName", "JobId"); + + b.ToTable("Logs", (string)null); + }); + + modelBuilder.Entity("Sloth.Core.Models.Scrubber", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("BatchDate") + .HasColumnType("datetime2"); + + b.Property("BatchSequenceNumber") + .HasColumnType("int"); + + b.Property("BlobId") + .HasColumnType("nvarchar(450)"); + + b.Property("SourceId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Uri") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("BlobId"); + + b.HasIndex("SourceId"); + + b.ToTable("Scrubbers"); + }); + + modelBuilder.Entity("Sloth.Core.Models.Source", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("Chart") + .HasMaxLength(2) + .HasColumnType("nvarchar(2)"); + + b.Property("Description") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("DocumentType") + .HasMaxLength(4) + .HasColumnType("nvarchar(4)"); + + b.Property("KfsFtpPasswordKeyName") + .HasColumnType("nvarchar(max)"); + + b.Property("KfsFtpUsername") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("OrganizationCode") + .HasMaxLength(4) + .HasColumnType("nvarchar(4)"); + + b.Property("OriginCode") + .HasMaxLength(2) + .HasColumnType("nvarchar(2)"); + + b.Property("TeamId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Type") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("TeamId"); + + b.ToTable("Sources"); + }); + + modelBuilder.Entity("Sloth.Core.Models.Team", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("KfsContactDepartmentName") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("nvarchar(30)"); + + b.Property("KfsContactEmail") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("nvarchar(40)"); + + b.Property("KfsContactMailingAddress") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("nvarchar(30)"); + + b.Property("KfsContactPhoneNumber") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("KfsContactUserId") + .IsRequired() + .HasMaxLength(8) + .HasColumnType("nvarchar(8)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Slug") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("nvarchar(40)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.HasIndex("Slug") + .IsUnique(); + + b.ToTable("Teams", (string)null); + }); + + modelBuilder.Entity("Sloth.Core.Models.TeamRole", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique() + .HasFilter("[Name] IS NOT NULL"); + + b.ToTable("TeamRoles"); + }); + + modelBuilder.Entity("Sloth.Core.Models.Transaction", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConsumerTrackingId") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("CreatorId") + .HasColumnType("nvarchar(450)"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("DocumentNumber") + .HasMaxLength(14) + .HasColumnType("nvarchar(14)"); + + b.Property("JournalRequestId") + .HasColumnType("nvarchar(450)"); + + b.Property("KfsTrackingNumber") + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("LastModified") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2") + .HasDefaultValueSql("SYSUTCDATETIME()"); + + b.Property("MerchantTrackingNumber") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("MerchantTrackingUrl") + .HasColumnType("nvarchar(max)"); + + b.Property("ProcessorTrackingNumber") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ReversalOfTransactionId") + .HasColumnType("nvarchar(450)"); + + b.Property("ReversalTransactionId") + .HasColumnType("nvarchar(450)"); + + b.Property("ScrubberId") + .HasColumnType("nvarchar(450)"); + + b.Property("SourceId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Status") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("TransactionDate") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("JournalRequestId"); + + b.HasIndex("KfsTrackingNumber"); + + b.HasIndex("LastModified"); + + b.HasIndex("MerchantTrackingNumber"); + + b.HasIndex("ProcessorTrackingNumber"); + + b.HasIndex("ReversalOfTransactionId") + .IsUnique() + .HasFilter("[ReversalOfTransactionId] IS NOT NULL"); + + b.HasIndex("ReversalTransactionId") + .IsUnique() + .HasFilter("[ReversalTransactionId] IS NOT NULL"); + + b.HasIndex("ScrubberId"); + + b.HasIndex("SourceId"); + + b.HasIndex("Status"); + + b.HasIndex("TransactionDate"); + + b.ToTable("Transactions"); + }); + + modelBuilder.Entity("Sloth.Core.Models.TransactionBlob", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("BlobId") + .HasColumnType("nvarchar(450)"); + + b.Property("IntegrationId") + .HasColumnType("nvarchar(450)"); + + b.Property("TransactionId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("BlobId"); + + b.HasIndex("IntegrationId"); + + b.HasIndex("TransactionId"); + + b.ToTable("TransactionBlobs"); + }); + + modelBuilder.Entity("Sloth.Core.Models.TransactionMetadata", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("TransactionId") + .HasColumnType("nvarchar(450)"); + + b.Property("Value") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("TransactionId"); + + b.HasIndex("TransactionId", "Name", "Value"); + + b.ToTable("TransactionMetadata"); + }); + + modelBuilder.Entity("Sloth.Core.Models.TransactionStatusEvent", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("EventDate") + .HasColumnType("datetime2"); + + b.Property("EventDetails") + .HasColumnType("nvarchar(max)"); + + b.Property("Status") + .HasColumnType("nvarchar(450)"); + + b.Property("TransactionId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("EventDate"); + + b.HasIndex("Status"); + + b.HasIndex("TransactionId"); + + b.ToTable("TransactionStatusEvents"); + }); + + modelBuilder.Entity("Sloth.Core.Models.Transfer", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("Account") + .HasMaxLength(7) + .HasColumnType("nvarchar(7)"); + + b.Property("AccountingDate") + .HasColumnType("datetime2"); + + b.Property("Amount") + .HasColumnType("decimal(18,2)"); + + b.Property("Chart") + .HasMaxLength(1) + .HasColumnType("nvarchar(1)"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("nvarchar(40)"); + + b.Property("Direction") + .HasColumnType("int"); + + b.Property("FinancialSegmentString") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("FiscalPeriod") + .HasColumnType("int"); + + b.Property("FiscalYear") + .HasColumnType("int"); + + b.Property("ObjectCode") + .HasMaxLength(4) + .HasColumnType("nvarchar(4)"); + + b.Property("ObjectType") + .HasMaxLength(2) + .HasColumnType("nvarchar(2)"); + + b.Property("Project") + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("ReferenceId") + .HasMaxLength(8) + .HasColumnType("nvarchar(8)"); + + b.Property("SequenceNumber") + .HasColumnType("int"); + + b.Property("SubAccount") + .HasMaxLength(5) + .HasColumnType("nvarchar(5)"); + + b.Property("SubObjectCode") + .HasMaxLength(3) + .HasColumnType("nvarchar(3)"); + + b.Property("TransactionId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("TransactionId"); + + b.ToTable("Transfers"); + }); + + modelBuilder.Entity("Sloth.Core.Models.User", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("FullName") + .HasColumnType("nvarchar(max)"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("Sloth.Core.Models.UserTeamRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.Property("TeamId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId", "TeamId"); + + b.HasIndex("RoleId"); + + b.HasIndex("TeamId"); + + b.ToTable("UserTeamRoles", (string)null); + }); + + modelBuilder.Entity("Sloth.Core.Models.WebHook", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ContentType") + .HasColumnType("nvarchar(max)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("TeamId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Url") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("TeamId"); + + b.ToTable("WebHooks"); + }); + + modelBuilder.Entity("Sloth.Core.Models.WebHookRequest", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("LastRequestDate") + .HasColumnType("datetime2"); + + b.Property("Payload") + .HasColumnType("nvarchar(max)"); + + b.Property("Persist") + .HasColumnType("bit"); + + b.Property("RequestCount") + .HasColumnType("int"); + + b.Property("ResponseBody") + .HasColumnType("nvarchar(max)"); + + b.Property("ResponseStatus") + .HasColumnType("int"); + + b.Property("WebHookId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("LastRequestDate"); + + b.HasIndex("ResponseStatus"); + + b.HasIndex("WebHookId"); + + b.ToTable("WebHookRequests"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Sloth.Core.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Sloth.Core.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Sloth.Core.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Sloth.Core.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Sloth.Core.Models.ApiKey", b => + { + b.HasOne("Sloth.Core.Models.Team", "Team") + .WithMany("ApiKeys") + .HasForeignKey("TeamId"); + + b.Navigation("Team"); + }); + + modelBuilder.Entity("Sloth.Core.Models.Integration", b => + { + b.HasOne("Sloth.Core.Models.Source", "Source") + .WithMany() + .HasForeignKey("SourceId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Sloth.Core.Models.Team", "Team") + .WithMany("Integrations") + .HasForeignKey("TeamId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Source"); + + b.Navigation("Team"); + }); + + modelBuilder.Entity("Sloth.Core.Models.JournalRequest", b => + { + b.HasOne("Sloth.Core.Models.Source", "Source") + .WithMany() + .HasForeignKey("SourceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Source"); + }); + + modelBuilder.Entity("Sloth.Core.Models.Scrubber", b => + { + b.HasOne("Sloth.Core.Models.Blob", "Blob") + .WithMany("Scrubbers") + .HasForeignKey("BlobId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("Sloth.Core.Models.Source", "Source") + .WithMany() + .HasForeignKey("SourceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Blob"); + + b.Navigation("Source"); + }); + + modelBuilder.Entity("Sloth.Core.Models.Source", b => + { + b.HasOne("Sloth.Core.Models.Team", "Team") + .WithMany("Sources") + .HasForeignKey("TeamId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Team"); + }); + + modelBuilder.Entity("Sloth.Core.Models.Transaction", b => + { + b.HasOne("Sloth.Core.Models.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("Sloth.Core.Models.JournalRequest", "JournalRequest") + .WithMany("Transactions") + .HasForeignKey("JournalRequestId"); + + b.HasOne("Sloth.Core.Models.Transaction", "ReversalOfTransaction") + .WithOne() + .HasForeignKey("Sloth.Core.Models.Transaction", "ReversalOfTransactionId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("Sloth.Core.Models.Transaction", "ReversalTransaction") + .WithOne() + .HasForeignKey("Sloth.Core.Models.Transaction", "ReversalTransactionId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("Sloth.Core.Models.Scrubber", "Scrubber") + .WithMany("Transactions") + .HasForeignKey("ScrubberId"); + + b.HasOne("Sloth.Core.Models.Source", "Source") + .WithMany() + .HasForeignKey("SourceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + + b.Navigation("JournalRequest"); + + b.Navigation("ReversalOfTransaction"); + + b.Navigation("ReversalTransaction"); + + b.Navigation("Scrubber"); + + b.Navigation("Source"); + }); + + modelBuilder.Entity("Sloth.Core.Models.TransactionBlob", b => + { + b.HasOne("Sloth.Core.Models.Blob", "Blob") + .WithMany("TransactionBlobs") + .HasForeignKey("BlobId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("Sloth.Core.Models.Integration", "Integration") + .WithMany("TransactionBlobs") + .HasForeignKey("IntegrationId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("Sloth.Core.Models.Transaction", "Transaction") + .WithMany("TransactionBlobs") + .HasForeignKey("TransactionId") + .OnDelete(DeleteBehavior.Restrict); + + b.Navigation("Blob"); + + b.Navigation("Integration"); + + b.Navigation("Transaction"); + }); + + modelBuilder.Entity("Sloth.Core.Models.TransactionMetadata", b => + { + b.HasOne("Sloth.Core.Models.Transaction", "Transaction") + .WithMany("Metadata") + .HasForeignKey("TransactionId") + .OnDelete(DeleteBehavior.Restrict); + + b.Navigation("Transaction"); + }); + + modelBuilder.Entity("Sloth.Core.Models.TransactionStatusEvent", b => + { + b.HasOne("Sloth.Core.Models.Transaction", "Transaction") + .WithMany("StatusEvents") + .HasForeignKey("TransactionId") + .OnDelete(DeleteBehavior.Restrict); + + b.Navigation("Transaction"); + }); + + modelBuilder.Entity("Sloth.Core.Models.Transfer", b => + { + b.HasOne("Sloth.Core.Models.Transaction", "Transaction") + .WithMany("Transfers") + .HasForeignKey("TransactionId"); + + b.Navigation("Transaction"); + }); + + modelBuilder.Entity("Sloth.Core.Models.UserTeamRole", b => + { + b.HasOne("Sloth.Core.Models.TeamRole", "Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Sloth.Core.Models.Team", "Team") + .WithMany("UserTeamRoles") + .HasForeignKey("TeamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Sloth.Core.Models.User", "User") + .WithMany("UserTeamRoles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + + b.Navigation("Team"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Sloth.Core.Models.WebHook", b => + { + b.HasOne("Sloth.Core.Models.Team", "Team") + .WithMany("WebHooks") + .HasForeignKey("TeamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Team"); + }); + + modelBuilder.Entity("Sloth.Core.Models.WebHookRequest", b => + { + b.HasOne("Sloth.Core.Models.WebHook", "WebHook") + .WithMany("WebHookrequests") + .HasForeignKey("WebHookId") + .OnDelete(DeleteBehavior.Restrict); + + b.Navigation("WebHook"); + }); + + modelBuilder.Entity("Sloth.Core.Models.Blob", b => + { + b.Navigation("Scrubbers"); + + b.Navigation("TransactionBlobs"); + }); + + modelBuilder.Entity("Sloth.Core.Models.Integration", b => + { + b.Navigation("TransactionBlobs"); + }); + + modelBuilder.Entity("Sloth.Core.Models.JournalRequest", b => + { + b.Navigation("Transactions"); + }); + + modelBuilder.Entity("Sloth.Core.Models.Scrubber", b => + { + b.Navigation("Transactions"); + }); + + modelBuilder.Entity("Sloth.Core.Models.Team", b => + { + b.Navigation("ApiKeys"); + + b.Navigation("Integrations"); + + b.Navigation("Sources"); + + b.Navigation("UserTeamRoles"); + + b.Navigation("WebHooks"); + }); + + modelBuilder.Entity("Sloth.Core.Models.Transaction", b => + { + b.Navigation("Metadata"); + + b.Navigation("StatusEvents"); + + b.Navigation("TransactionBlobs"); + + b.Navigation("Transfers"); + }); + + modelBuilder.Entity("Sloth.Core.Models.User", b => + { + b.Navigation("UserTeamRoles"); + }); + + modelBuilder.Entity("Sloth.Core.Models.WebHook", b => + { + b.Navigation("WebHookrequests"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sloth.Core/Migrations/20231106230628_MetadataIndex.cs b/Sloth.Core/Migrations/20231106230628_MetadataIndex.cs new file mode 100644 index 00000000..e0cbff23 --- /dev/null +++ b/Sloth.Core/Migrations/20231106230628_MetadataIndex.cs @@ -0,0 +1,40 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Sloth.Core.Migrations +{ + public partial class MetadataIndex : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Value", + table: "TransactionMetadata", + type: "nvarchar(450)", + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(max)"); + + migrationBuilder.CreateIndex( + name: "IX_TransactionMetadata_TransactionId_Name_Value", + table: "TransactionMetadata", + columns: new[] { "TransactionId", "Name", "Value" }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_TransactionMetadata_TransactionId_Name_Value", + table: "TransactionMetadata"); + + migrationBuilder.AlterColumn( + name: "Value", + table: "TransactionMetadata", + type: "nvarchar(max)", + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(450)"); + } + } +} diff --git a/Sloth.Core/Migrations/SlothDbContextModelSnapshot.cs b/Sloth.Core/Migrations/SlothDbContextModelSnapshot.cs index 0dbe249e..0028aa07 100644 --- a/Sloth.Core/Migrations/SlothDbContextModelSnapshot.cs +++ b/Sloth.Core/Migrations/SlothDbContextModelSnapshot.cs @@ -679,12 +679,14 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("Value") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("nvarchar(450)"); b.HasKey("Id"); b.HasIndex("TransactionId"); + b.HasIndex("TransactionId", "Name", "Value"); + b.ToTable("TransactionMetadata"); }); diff --git a/Sloth.Core/SlothDbContext.cs b/Sloth.Core/SlothDbContext.cs index 261d8589..676861b5 100644 --- a/Sloth.Core/SlothDbContext.cs +++ b/Sloth.Core/SlothDbContext.cs @@ -146,6 +146,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) WebHookRequest.OnModelCreating(modelBuilder); JobRecord.OnModelCreating(modelBuilder); TransactionBlob.OnModelCreating(modelBuilder); + TransactionMetadata.OnModelCreating(modelBuilder); } } }