diff --git a/src/Abm.Pyro.Repository/EntityConfiguration/ComparatorEntityConfig.cs b/src/Abm.Pyro.Repository/EntityConfiguration/ComparatorEntityConfig.cs new file mode 100644 index 0000000..f1057a8 --- /dev/null +++ b/src/Abm.Pyro.Repository/EntityConfiguration/ComparatorEntityConfig.cs @@ -0,0 +1,23 @@ +using Abm.Pyro.Domain.Enums; +using Abm.Pyro.Domain.Model; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Abm.Pyro.Repository.EntityConfiguration; + +public class ComparatorEntityConfig : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + // Comparator --------------------------------------------------------------- + builder.HasKey(x => x.SearchComparatorId); + + builder.Property(x => x.SearchComparatorId).HasConversion(); + builder.Property(x => x.Name).HasMaxLength(RepositoryModelConstraints.CodeMaxLength); + + builder.HasData( + Enum.GetValues(typeof(SearchComparatorId)) + .Cast() + .Select(e => new Comparator(e, e.ToString()))); + } +} \ No newline at end of file diff --git a/src/Abm.Pyro.Repository/EntityConfiguration/HttpVerbEntityConfig.cs b/src/Abm.Pyro.Repository/EntityConfiguration/HttpVerbEntityConfig.cs new file mode 100644 index 0000000..824271c --- /dev/null +++ b/src/Abm.Pyro.Repository/EntityConfiguration/HttpVerbEntityConfig.cs @@ -0,0 +1,23 @@ +using Abm.Pyro.Domain.Enums; +using Abm.Pyro.Domain.Model; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Abm.Pyro.Repository.EntityConfiguration; + +public class HttpVerbEntityConfig : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + // HttpVerb ----------------------------------------------------------------- + builder.HasKey(x => x.HttpVerbId); + + builder.Property(x => x.HttpVerbId).HasConversion(); + builder.Property(x => x.Name).HasMaxLength(RepositoryModelConstraints.CodeMaxLength); + + builder.HasData( + Enum.GetValues(typeof(HttpVerbId)) + .Cast() + .Select(e => new HttpVerb(e, e.ToString()))); + } +} \ No newline at end of file diff --git a/src/Abm.Pyro.Repository/EntityConfiguration/IndexDateTimeEntityConfig.cs b/src/Abm.Pyro.Repository/EntityConfiguration/IndexDateTimeEntityConfig.cs new file mode 100644 index 0000000..c607ebc --- /dev/null +++ b/src/Abm.Pyro.Repository/EntityConfiguration/IndexDateTimeEntityConfig.cs @@ -0,0 +1,17 @@ +using Abm.Pyro.Domain.Model; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Abm.Pyro.Repository.EntityConfiguration; + +public class IndexDateTimeEntityConfig : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + // IndexDateTime --------------------------------------------------------------- + builder.HasKey(x => x.IndexDateTimeId); + builder.HasIndex(x => x.LowUtc); + builder.HasIndex(x => x.HighUtc); + + } +} \ No newline at end of file diff --git a/src/Abm.Pyro.Repository/EntityConfiguration/IndexQuantityEntityConfig.cs b/src/Abm.Pyro.Repository/EntityConfiguration/IndexQuantityEntityConfig.cs new file mode 100644 index 0000000..d242c42 --- /dev/null +++ b/src/Abm.Pyro.Repository/EntityConfiguration/IndexQuantityEntityConfig.cs @@ -0,0 +1,47 @@ +using Abm.Pyro.Domain.Model; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Abm.Pyro.Repository.EntityConfiguration; + +public class IndexQuantityEntityConfig : IEntityTypeConfiguration +{ + public void Configure( + EntityTypeBuilder builder) + { + // IndexQuantity --------------------------------------------------------------- + builder.HasKey(x => x.IndexQuantityId); + builder.HasIndex(x => x.Code); + builder.HasIndex(x => x.System); + builder.HasIndex(x => x.Quantity); + builder.HasIndex(x => x.CodeHigh); + builder.HasIndex(x => x.SystemHigh); + builder.HasIndex(x => x.QuantityHigh); + + builder.Property(x => x.Code).HasMaxLength(RepositoryModelConstraints.CodeMaxLength); + builder.Property(x => x.System).HasMaxLength(RepositoryModelConstraints.StringMaxLength); + builder.Property(x => x.Quantity).HasPrecision( + RepositoryModelConstraints.QuantityPrecision, + RepositoryModelConstraints.QuantityScale); + builder.Property(x => x.Unit).HasMaxLength(RepositoryModelConstraints.CodeMaxLength); + + builder.Property(x => x.CodeHigh).HasMaxLength(RepositoryModelConstraints.CodeMaxLength); + builder.Property(x => x.SystemHigh).HasMaxLength(RepositoryModelConstraints.StringMaxLength); + builder.Property(x => x.QuantityHigh).HasPrecision( + RepositoryModelConstraints.QuantityPrecision, + RepositoryModelConstraints.QuantityScale); + builder.Property(x => x.UnitHigh).HasMaxLength(RepositoryModelConstraints.CodeMaxLength); + + builder + .HasOne(x => x.ResourceStore) + .WithMany(x => x.IndexQuantityList) + .HasForeignKey(x => x.ResourceStoreId) + .OnDelete(DeleteBehavior.Cascade); + + builder + .HasOne(x => x.SearchParameterStore) + .WithMany() + .HasForeignKey(x => x.SearchParameterStoreId) + .OnDelete(DeleteBehavior.NoAction); + } +} \ No newline at end of file diff --git a/src/Abm.Pyro.Repository/EntityConfiguration/IndexReferenceEntityConfig.cs b/src/Abm.Pyro.Repository/EntityConfiguration/IndexReferenceEntityConfig.cs new file mode 100644 index 0000000..a9ec806 --- /dev/null +++ b/src/Abm.Pyro.Repository/EntityConfiguration/IndexReferenceEntityConfig.cs @@ -0,0 +1,45 @@ +using Abm.Pyro.Domain.Model; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Abm.Pyro.Repository.EntityConfiguration; + +public class IndexReferenceEntityConfig : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + // IndexReference --------------------------------------------------------------- + + builder.HasKey(x => x.IndexReferenceId); + builder.HasIndex(x => x.ResourceId); + builder.HasIndex(x => x.VersionId); + builder.HasIndex(x => x.CanonicalVersionId); + + builder.Property(x => x.ResourceId) + .UseCollation(RepositoryModelConstraints.CaseSensitive) + .HasMaxLength(RepositoryModelConstraints.FhirIdMaxLength); + builder.Property(x => x.VersionId) + .HasMaxLength(RepositoryModelConstraints.FhirIdMaxLength); + builder.Property(x => x.CanonicalVersionId) + .HasMaxLength(RepositoryModelConstraints.FhirIdMaxLength); + + builder + .HasOne(x => x.ResourceStore) + .WithMany(x => x.IndexReferenceList) + .HasForeignKey(x => x.ResourceStoreId) + .OnDelete(DeleteBehavior.Cascade); + + builder + .HasOne(x => x.ServiceBaseUrl) + .WithMany() + .HasForeignKey(x => x.ServiceBaseUrlId) + .OnDelete(DeleteBehavior.NoAction); + + builder + .HasOne(x => x.SearchParameterStore) + .WithMany() + .HasForeignKey(x => x.SearchParameterStoreId) + .OnDelete(DeleteBehavior.NoAction); + + } +} \ No newline at end of file diff --git a/src/Abm.Pyro.Repository/EntityConfiguration/IndexStringEntityConfig.cs b/src/Abm.Pyro.Repository/EntityConfiguration/IndexStringEntityConfig.cs new file mode 100644 index 0000000..7cefa55 --- /dev/null +++ b/src/Abm.Pyro.Repository/EntityConfiguration/IndexStringEntityConfig.cs @@ -0,0 +1,30 @@ +using Abm.Pyro.Domain.Model; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Abm.Pyro.Repository.EntityConfiguration; + +public class IndexStringEntityConfig : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + // IndexString --------------------------------------------------------------- + builder.HasKey(x => x.IndexStringId); + builder.HasIndex(x => x.Value); + + builder.Property(x => x.Value); + + builder + .HasOne(x => x.ResourceStore) + .WithMany(x => x.IndexStringList) + .HasForeignKey(x => x.ResourceStoreId) + .OnDelete(DeleteBehavior.Cascade); + + builder + .HasOne(x => x.SearchParameterStore) + .WithMany() + .HasForeignKey(x => x.SearchParameterStoreId) + .OnDelete(DeleteBehavior.NoAction); + + } +} \ No newline at end of file diff --git a/src/Abm.Pyro.Repository/EntityConfiguration/IndexTokenEntityConfig.cs b/src/Abm.Pyro.Repository/EntityConfiguration/IndexTokenEntityConfig.cs new file mode 100644 index 0000000..195c3ea --- /dev/null +++ b/src/Abm.Pyro.Repository/EntityConfiguration/IndexTokenEntityConfig.cs @@ -0,0 +1,31 @@ +using Abm.Pyro.Domain.Model; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Abm.Pyro.Repository.EntityConfiguration; + +public class IndexTokenEntityConfig : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + // IndexToken --------------------------------------------------------------- + builder.HasKey(x => x.IndexTokenId); + builder.HasIndex(x => x.System); + builder.HasIndex(x => x.Code); + + builder.Property(x => x.System).HasMaxLength(RepositoryModelConstraints.StringMaxLength); + builder.Property(x => x.Code).HasMaxLength(RepositoryModelConstraints.CodeMaxLength); + + builder + .HasOne(x => x.ResourceStore) + .WithMany(x => x.IndexTokenList) + .HasForeignKey(x => x.ResourceStoreId) + .OnDelete(DeleteBehavior.Cascade); + + builder + .HasOne(x => x.SearchParameterStore) + .WithMany() + .HasForeignKey(x => x.SearchParameterStoreId) + .OnDelete(DeleteBehavior.NoAction); + } +} \ No newline at end of file diff --git a/src/Abm.Pyro.Repository/EntityConfiguration/IndexUriEntityConfig.cs b/src/Abm.Pyro.Repository/EntityConfiguration/IndexUriEntityConfig.cs new file mode 100644 index 0000000..afcf0a3 --- /dev/null +++ b/src/Abm.Pyro.Repository/EntityConfiguration/IndexUriEntityConfig.cs @@ -0,0 +1,29 @@ +using Abm.Pyro.Domain.Model; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Abm.Pyro.Repository.EntityConfiguration; + +public class IndexUriEntityConfig : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + // IndexUri --------------------------------------------------------------- + builder.HasKey(x => x.IndexUriId); + builder.HasIndex(x => x.Uri); + + builder.Property(x => x.Uri).HasMaxLength(RepositoryModelConstraints.StringMaxLength);; + + builder + .HasOne(x => x.ResourceStore) + .WithMany(x => x.IndexUriList) + .HasForeignKey(x => x.ResourceStoreId) + .OnDelete(DeleteBehavior.Cascade); + + builder + .HasOne(x => x.SearchParameterStore) + .WithMany() + .HasForeignKey(x => x.SearchParameterStoreId) + .OnDelete(DeleteBehavior.NoAction); + } +} \ No newline at end of file diff --git a/src/Abm.Pyro.Repository/EntityConfiguration/PublicationStatusEntityConfig.cs b/src/Abm.Pyro.Repository/EntityConfiguration/PublicationStatusEntityConfig.cs new file mode 100644 index 0000000..0a80532 --- /dev/null +++ b/src/Abm.Pyro.Repository/EntityConfiguration/PublicationStatusEntityConfig.cs @@ -0,0 +1,23 @@ +using Abm.Pyro.Domain.Enums; +using Abm.Pyro.Domain.Model; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Abm.Pyro.Repository.EntityConfiguration; + +public class PublicationStatusEntityConfig : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + // PublicationStatus -------------------------------------------------------- + builder.HasKey(x => x.PublicationStatusId); + + builder.Property(x => x.PublicationStatusId).HasConversion(); + builder.Property(x => x.Name).HasMaxLength(RepositoryModelConstraints.CodeMaxLength); + + builder.HasData( + Enum.GetValues(typeof(PublicationStatusId)) + .Cast() + .Select(e => new PublicationStatus(e, e.ToString()))); + } +} \ No newline at end of file diff --git a/src/Abm.Pyro.Repository/EntityMapping/ResourceStoreMapping.cs b/src/Abm.Pyro.Repository/EntityConfiguration/ResourceStoreEntityConfig.cs similarity index 90% rename from src/Abm.Pyro.Repository/EntityMapping/ResourceStoreMapping.cs rename to src/Abm.Pyro.Repository/EntityConfiguration/ResourceStoreEntityConfig.cs index f02bc8b..f8a1e9a 100644 --- a/src/Abm.Pyro.Repository/EntityMapping/ResourceStoreMapping.cs +++ b/src/Abm.Pyro.Repository/EntityConfiguration/ResourceStoreEntityConfig.cs @@ -2,9 +2,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace Abm.Pyro.Repository.EntityMapping; +namespace Abm.Pyro.Repository.EntityConfiguration; -public class ResourceStoreMapping : IEntityTypeConfiguration +public class ResourceStoreEntityConfig : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { diff --git a/src/Abm.Pyro.Repository/EntityConfiguration/ResourceTypeEntityConfig.cs b/src/Abm.Pyro.Repository/EntityConfiguration/ResourceTypeEntityConfig.cs new file mode 100644 index 0000000..746ed71 --- /dev/null +++ b/src/Abm.Pyro.Repository/EntityConfiguration/ResourceTypeEntityConfig.cs @@ -0,0 +1,23 @@ +using Abm.Pyro.Domain.Enums; +using Abm.Pyro.Domain.Model; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Abm.Pyro.Repository.EntityConfiguration; + +public class ResourceTypeEntityConfig : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + // ResourceType --------------------------------------------------------------- + builder.HasKey(x => x.FhirResourceType); + + builder.Property(x => x.FhirResourceType).HasConversion(); + builder.Property(x => x.Name).HasMaxLength(RepositoryModelConstraints.FhirResourceNameMaxLength); + + builder.HasData( + Enum.GetValues(typeof(FhirResourceTypeId)) + .Cast() + .Select(e => new ResourceType(e, e.ToString()))); + } +} \ No newline at end of file diff --git a/src/Abm.Pyro.Repository/EntityConfiguration/SearchModifierCodeEntityConfig.cs b/src/Abm.Pyro.Repository/EntityConfiguration/SearchModifierCodeEntityConfig.cs new file mode 100644 index 0000000..de732ba --- /dev/null +++ b/src/Abm.Pyro.Repository/EntityConfiguration/SearchModifierCodeEntityConfig.cs @@ -0,0 +1,23 @@ +using Abm.Pyro.Domain.Enums; +using Abm.Pyro.Domain.Model; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Abm.Pyro.Repository.EntityConfiguration; + +public class SearchModifierCodeEntityConfig : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + // SearchModifierCode --------------------------------------------------------------- + builder.HasKey(x => x.SearchModifierCodeId); + + builder.Property(x => x.SearchModifierCodeId).HasConversion(); + builder.Property(x => x.Name).HasMaxLength(RepositoryModelConstraints.CodeMaxLength); + + builder.HasData( + Enum.GetValues(typeof(SearchModifierCodeId)) + .Cast() + .Select(e => new SearchModifierCode(e, e.ToString()))); + } +} \ No newline at end of file diff --git a/src/Abm.Pyro.Repository/EntityConfiguration/SearchParameterStoreComparatorEntityConfig.cs b/src/Abm.Pyro.Repository/EntityConfiguration/SearchParameterStoreComparatorEntityConfig.cs new file mode 100644 index 0000000..f10922f --- /dev/null +++ b/src/Abm.Pyro.Repository/EntityConfiguration/SearchParameterStoreComparatorEntityConfig.cs @@ -0,0 +1,20 @@ +using Abm.Pyro.Domain.Model; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Abm.Pyro.Repository.EntityConfiguration; + +public class SearchParameterStoreComparatorEntityConfig : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + // SearchParameterStoreComparator --------------------------------------------------------------- + builder.HasKey(x => x.SearchParameterStoreComparatorId); + builder.HasIndex(x => x.SearchParameterStoreId); + + builder.Property(x => x.SearchParameterStoreId); + builder.Property(x => x.SearchComparatorId).HasConversion(); + builder.HasData(Seed.SearchParameterStoreComparatorSeed.Get()); + + } +} \ No newline at end of file diff --git a/src/Abm.Pyro.Repository/EntityConfiguration/SearchParameterStoreComponentEntityConfig.cs b/src/Abm.Pyro.Repository/EntityConfiguration/SearchParameterStoreComponentEntityConfig.cs new file mode 100644 index 0000000..81e3c71 --- /dev/null +++ b/src/Abm.Pyro.Repository/EntityConfiguration/SearchParameterStoreComponentEntityConfig.cs @@ -0,0 +1,20 @@ +using Abm.Pyro.Domain.Model; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Abm.Pyro.Repository.EntityConfiguration; + +public class SearchParameterStoreComponentEntityConfig : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + // SearchParameterStoreComponent --------------------------------------------------------------- + builder.HasKey(x => x.SearchParameterStoreComponentId); + builder.HasIndex(x => x.SearchParameterStoreId); + + builder.Property(x => x.SearchParameterStoreId); + builder.Property(x => x.Definition); + builder.Property(x => x.Expression); + builder.HasData(Seed.SearchParameterStoreComponentSeed.Get()); + } +} \ No newline at end of file diff --git a/src/Abm.Pyro.Repository/EntityConfiguration/SearchParameterStoreEntityConfig.cs b/src/Abm.Pyro.Repository/EntityConfiguration/SearchParameterStoreEntityConfig.cs new file mode 100644 index 0000000..1a2be12 --- /dev/null +++ b/src/Abm.Pyro.Repository/EntityConfiguration/SearchParameterStoreEntityConfig.cs @@ -0,0 +1,66 @@ +using Abm.Pyro.Domain.Model; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Abm.Pyro.Repository.EntityConfiguration; + +public class SearchParameterStoreEntityConfig : IEntityTypeConfiguration +{ + public void Configure( + EntityTypeBuilder builder) + { + // SearchParameterStore ------------------------------------------------------ + + builder.HasKey(x => x.SearchParameterStoreId); + builder.HasAlternateKey(x => x.ResourceId); + builder.HasIndex(x => x.VersionId); + builder.HasIndex(x => x.Code); + + builder.Property(x => x.ResourceId) + .UseCollation(RepositoryModelConstraints.CaseSensitive) + .HasMaxLength(RepositoryModelConstraints.FhirIdMaxLength); + builder.Property(x => x.VersionId).HasMaxLength(RepositoryModelConstraints.FhirIdMaxLength); + builder.Property(x => x.IsCurrent); + builder.Property(x => x.IsDeleted); + builder.Property(x => x.IsIndexed); + builder.Property(x => x.Name).HasMaxLength(RepositoryModelConstraints.CodeMaxLength); + builder.Property(x => x.Status).HasConversion(); + builder.Property(x => x.Url); + builder.Property(x => x.Code).HasMaxLength(RepositoryModelConstraints.CodeMaxLength); + builder.Property(x => x.Type); + builder.Property(x => x.Expression); + builder.Property(x => x.MultipleOr); + builder.Property(x => x.MultipleAnd); + builder.Property(x => x.Chain); + builder.Property(x => x.Json); + builder.Property(x => x.LastUpdated).HasPrecision(RepositoryModelConstraints.TimestampPrecision); + builder.Property(x => x.RowVersion).IsConcurrencyToken(); + + builder + .HasMany(x => x.ComparatorList) + .WithOne(x => x.SearchParameterStore) + .HasForeignKey(x => x.SearchParameterStoreId); + + builder + .HasMany(x => x.BaseList) + .WithOne(x => x.SearchParameterStore) + .HasForeignKey(x => x.SearchParameterStoreId); + + builder + .HasMany(x => x.TargetList) + .WithOne(x => x.SearchParameterStore) + .HasForeignKey(x => x.SearchParameterStoreId); + + builder + .HasMany(x => x.ModifierList) + .WithOne(x => x.SearchParameterStore) + .HasForeignKey(x => x.SearchParameterStoreId); + + builder + .HasMany(x => x.ComponentList) + .WithOne(x => x.SearchParameterStore) + .HasForeignKey(x => x.SearchParameterStoreId); + + builder.HasData(Seed.SearchParameterSeed.Get()); + } +} \ No newline at end of file diff --git a/src/Abm.Pyro.Repository/EntityConfiguration/SearchParameterStoreResourceTypeBaseEntityConfig.cs b/src/Abm.Pyro.Repository/EntityConfiguration/SearchParameterStoreResourceTypeBaseEntityConfig.cs new file mode 100644 index 0000000..08e8fb5 --- /dev/null +++ b/src/Abm.Pyro.Repository/EntityConfiguration/SearchParameterStoreResourceTypeBaseEntityConfig.cs @@ -0,0 +1,20 @@ +using Abm.Pyro.Domain.Model; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Abm.Pyro.Repository.EntityConfiguration; + +public class + SearchParameterStoreResourceTypeBaseEntityConfig : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + // SearchParameterStoreResourceTypeBase --------------------------------------------------------------- + builder.HasKey(x => x.SearchParameterStoreResourceTypeBaseId); + builder.HasIndex(x => x.SearchParameterStoreId); + + builder.Property(x => x.SearchParameterStoreId); + builder.Property(x => x.ResourceType).HasConversion(); + builder.HasData(Seed.SearchParameterStoreResourceTypeBaseSeed.Get()); + } +} \ No newline at end of file diff --git a/src/Abm.Pyro.Repository/EntityConfiguration/SearchParameterStoreResourceTypeTargetEntityConfig.cs b/src/Abm.Pyro.Repository/EntityConfiguration/SearchParameterStoreResourceTypeTargetEntityConfig.cs new file mode 100644 index 0000000..a0c7500 --- /dev/null +++ b/src/Abm.Pyro.Repository/EntityConfiguration/SearchParameterStoreResourceTypeTargetEntityConfig.cs @@ -0,0 +1,20 @@ +using Abm.Pyro.Domain.Model; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Abm.Pyro.Repository.EntityConfiguration; + +public class SearchParameterStoreResourceTypeTargetEntityConfig : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + // SearchParameterStoreResourceTypeTarget --------------------------------------------------------------- + builder.HasKey(x => x.SearchParameterStoreResourceTypeTargetId); + builder.HasIndex(x => x.SearchParameterStoreId); + + builder.Property(x => x.SearchParameterStoreId); + builder.Property(x => x.ResourceType).HasConversion(); + builder.HasData(Seed.SearchParameterStoreResourceTypeTargetSeed.Get()); + + } +} \ No newline at end of file diff --git a/src/Abm.Pyro.Repository/EntityConfiguration/SearchParameterStoreSearchModifierCodeEntityConfig.cs b/src/Abm.Pyro.Repository/EntityConfiguration/SearchParameterStoreSearchModifierCodeEntityConfig.cs new file mode 100644 index 0000000..fa89970 --- /dev/null +++ b/src/Abm.Pyro.Repository/EntityConfiguration/SearchParameterStoreSearchModifierCodeEntityConfig.cs @@ -0,0 +1,20 @@ +using Abm.Pyro.Domain.Model; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Abm.Pyro.Repository.EntityConfiguration; + +public class SearchParameterStoreSearchModifierCodeEntityConfig : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + // SearchParameterStoreSearchModifierCode --------------------------------------------------------------- + builder.HasKey(x => x.SearchParameterStoreSearchModifierCodeId); + builder.HasIndex(x => x.SearchParameterStoreId); + + builder.Property(x => x.SearchParameterStoreId); + builder.Property(x => x.SearchModifierCodeId).HasConversion(); + builder.HasData(Seed.SearchParameterStoreSearchModifierCodeSeed.Get()); + + } +} \ No newline at end of file diff --git a/src/Abm.Pyro.Repository/EntityConfiguration/ServiceBaseUrlEntityConfig.cs b/src/Abm.Pyro.Repository/EntityConfiguration/ServiceBaseUrlEntityConfig.cs new file mode 100644 index 0000000..217af1b --- /dev/null +++ b/src/Abm.Pyro.Repository/EntityConfiguration/ServiceBaseUrlEntityConfig.cs @@ -0,0 +1,25 @@ +using Abm.Pyro.Domain.Model; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Abm.Pyro.Repository.EntityConfiguration; + +public class ServiceBaseUrlEntityConfig : IEntityTypeConfiguration +{ + public void Configure( + EntityTypeBuilder builder) + { + // ServiceBaseUrl --------------------------------------------------------------- + + builder.HasKey(x => x.ServiceBaseUrlId); + + // ReSharper disable once EntityNameCapturedOnly.Local + ServiceBaseUrl serviceBaseUrlForPropertyNameCaptureOnly; + builder.HasIndex(x => new { x.Url, x.IsPrimary }) + .IsUnique() + .HasFilter($"[{nameof(serviceBaseUrlForPropertyNameCaptureOnly.IsPrimary)}] = 1"); + + builder.Property(x => x.IsPrimary); + builder.Property(x => x.Url).UseCollation(RepositoryModelConstraints.CaseSensitive); + } +} \ No newline at end of file diff --git a/src/Abm.Pyro.Repository/PyroDbContext.cs b/src/Abm.Pyro.Repository/PyroDbContext.cs index e46fca9..39b257b 100644 --- a/src/Abm.Pyro.Repository/PyroDbContext.cs +++ b/src/Abm.Pyro.Repository/PyroDbContext.cs @@ -1,344 +1,56 @@ using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Abm.Pyro.Domain.Enums; using Abm.Pyro.Domain.Model; using Abm.Pyro.Repository.Conversion; -using Abm.Pyro.Repository.EntityMapping; +using Abm.Pyro.Repository.EntityConfiguration; namespace Abm.Pyro.Repository; - public class PyroDbContext : DbContext - { - public DbSet ResourceStore => Set(); +public class PyroDbContext : DbContext +{ + public DbSet ResourceStore => Set(); public DbSet IndexString => Set(); public DbSet IndexReference => Set(); public DbSet SearchParameterStore => Set(); public DbSet ServiceBaseUrl => Set(); - - - // public PyroDbContext(DbContextOptions contextOptions) - // : base(contextOptions) - // { - // } - - public PyroDbContext(DbContextOptions options) + + public PyroDbContext( + DbContextOptions options) : base(options) { - } - + protected override void OnModelCreating(ModelBuilder modelBuilder) { - // EntityTypeConfiguration ----------------------------------------------------------- - //modelBuilder.UseCollation(RepositoryModelConstraints.CaseInsensitive); - modelBuilder.ApplyConfiguration(new ResourceStoreJsonCompressionConversion()); - - //Entity Configurations - modelBuilder.ApplyConfiguration(new ResourceStoreMapping()); - - - // IndexString --------------------------------------------------------------- - modelBuilder.Entity().HasKey(x => x.IndexStringId); - modelBuilder.Entity().HasIndex(x => x.Value); - - modelBuilder.Entity().Property(x => x.Value); - - modelBuilder.Entity() - .HasOne(x => x.ResourceStore) - .WithMany(x => x.IndexStringList) - .HasForeignKey(x => x.ResourceStoreId) - .OnDelete(DeleteBehavior.Cascade); - - modelBuilder.Entity() - .HasOne(x => x.SearchParameterStore) - .WithMany() - .HasForeignKey(x => x.SearchParameterStoreId) - .OnDelete(DeleteBehavior.NoAction); - - // IndexReference --------------------------------------------------------------- - modelBuilder.Entity().HasKey(x => x.IndexReferenceId); - modelBuilder.Entity().HasIndex(x => x.ResourceId); - modelBuilder.Entity().HasIndex(x => x.VersionId); - modelBuilder.Entity().HasIndex(x => x.CanonicalVersionId); - - modelBuilder.Entity().Property(x => x.ResourceId) - .UseCollation(RepositoryModelConstraints.CaseSensitive) - .HasMaxLength(RepositoryModelConstraints.FhirIdMaxLength); - modelBuilder.Entity().Property(x => x.VersionId) - .HasMaxLength(RepositoryModelConstraints.FhirIdMaxLength); - modelBuilder.Entity().Property(x => x.CanonicalVersionId) - .HasMaxLength(RepositoryModelConstraints.FhirIdMaxLength); - - modelBuilder.Entity() - .HasOne(x => x.ResourceStore) - .WithMany(x => x.IndexReferenceList) - .HasForeignKey(x => x.ResourceStoreId) - .OnDelete(DeleteBehavior.Cascade); - - modelBuilder.Entity() - .HasOne(x => x.ServiceBaseUrl) - .WithMany() - .HasForeignKey(x => x.ServiceBaseUrlId) - .OnDelete(DeleteBehavior.NoAction); - - modelBuilder.Entity() - .HasOne(x => x.SearchParameterStore) - .WithMany() - .HasForeignKey(x => x.SearchParameterStoreId) - .OnDelete(DeleteBehavior.NoAction); - - // IndexDateTime --------------------------------------------------------------- - modelBuilder.Entity().HasKey(x => x.IndexDateTimeId); - modelBuilder.Entity().HasIndex(x => x.LowUtc); - modelBuilder.Entity().HasIndex(x => x.HighUtc); - - modelBuilder.Entity().Property(x => x.LowUtc); - modelBuilder.Entity().Property(x => x.HighUtc); - - modelBuilder.Entity() - .HasOne(x => x.ResourceStore) - .WithMany(x => x.IndexDateTimeList) - .HasForeignKey(x => x.ResourceStoreId) - .OnDelete(DeleteBehavior.Cascade); - - modelBuilder.Entity() - .HasOne(x => x.SearchParameterStore) - .WithMany() - .HasForeignKey(x => x.SearchParameterStoreId) - .OnDelete(DeleteBehavior.NoAction); - - // IndexQuantity --------------------------------------------------------------- - modelBuilder.Entity().HasKey(x => x.IndexQuantityId); - modelBuilder.Entity().HasIndex(x => x.Code); - modelBuilder.Entity().HasIndex(x => x.System); - modelBuilder.Entity().HasIndex(x => x.Quantity); - modelBuilder.Entity().HasIndex(x => x.CodeHigh); - modelBuilder.Entity().HasIndex(x => x.SystemHigh); - modelBuilder.Entity().HasIndex(x => x.QuantityHigh); - - modelBuilder.Entity().Property(x => x.Code).HasMaxLength(RepositoryModelConstraints.CodeMaxLength); - modelBuilder.Entity().Property(x => x.System).HasMaxLength(RepositoryModelConstraints.StringMaxLength); - modelBuilder.Entity().Property(x => x.Quantity).HasPrecision(RepositoryModelConstraints.QuantityPrecision, RepositoryModelConstraints.QuantityScale); - modelBuilder.Entity().Property(x => x.Unit).HasMaxLength(RepositoryModelConstraints.CodeMaxLength);; - modelBuilder.Entity().Property(x => x.CodeHigh).HasMaxLength(RepositoryModelConstraints.CodeMaxLength);; - modelBuilder.Entity().Property(x => x.SystemHigh).HasMaxLength(RepositoryModelConstraints.StringMaxLength); - modelBuilder.Entity().Property(x => x.QuantityHigh).HasPrecision(RepositoryModelConstraints.QuantityPrecision, RepositoryModelConstraints.QuantityScale); - modelBuilder.Entity().Property(x => x.UnitHigh).HasMaxLength(RepositoryModelConstraints.CodeMaxLength);; - - modelBuilder.Entity() - .HasOne(x => x.ResourceStore) - .WithMany(x => x.IndexQuantityList) - .HasForeignKey(x => x.ResourceStoreId) - .OnDelete(DeleteBehavior.Cascade); - - modelBuilder.Entity() - .HasOne(x => x.SearchParameterStore) - .WithMany() - .HasForeignKey(x => x.SearchParameterStoreId) - .OnDelete(DeleteBehavior.NoAction); - - // IndexToken --------------------------------------------------------------- - modelBuilder.Entity().HasKey(x => x.IndexTokenId); - modelBuilder.Entity().HasIndex(x => x.System); - modelBuilder.Entity().HasIndex(x => x.Code); - - modelBuilder.Entity().Property(x => x.System).HasMaxLength(RepositoryModelConstraints.StringMaxLength);; - modelBuilder.Entity().Property(x => x.Code).HasMaxLength(RepositoryModelConstraints.CodeMaxLength);; - - modelBuilder.Entity() - .HasOne(x => x.ResourceStore) - .WithMany(x => x.IndexTokenList) - .HasForeignKey(x => x.ResourceStoreId) - .OnDelete(DeleteBehavior.Cascade); - - modelBuilder.Entity() - .HasOne(x => x.SearchParameterStore) - .WithMany() - .HasForeignKey(x => x.SearchParameterStoreId) - .OnDelete(DeleteBehavior.NoAction); - - // IndexUri --------------------------------------------------------------- - modelBuilder.Entity().HasKey(x => x.IndexUriId); - modelBuilder.Entity().HasIndex(x => x.Uri); - - modelBuilder.Entity().Property(x => x.Uri).HasMaxLength(RepositoryModelConstraints.StringMaxLength);; - - modelBuilder.Entity() - .HasOne(x => x.ResourceStore) - .WithMany(x => x.IndexUriList) - .HasForeignKey(x => x.ResourceStoreId) - .OnDelete(DeleteBehavior.Cascade); - - modelBuilder.Entity() - .HasOne(x => x.SearchParameterStore) - .WithMany() - .HasForeignKey(x => x.SearchParameterStoreId) - .OnDelete(DeleteBehavior.NoAction); - - // ServiceBaseUrl --------------------------------------------------------------- - - - modelBuilder.Entity().HasKey(x => x.ServiceBaseUrlId); - // ReSharper disable once EntityNameCapturedOnly.Local - ServiceBaseUrl serviceBaseUrlForPropertyNameCaptureOnly; - modelBuilder.Entity().HasIndex(x => new { x.Url, x.IsPrimary }) - .IsUnique() - .HasFilter($"[{nameof(serviceBaseUrlForPropertyNameCaptureOnly.IsPrimary)}] = 1"); - - modelBuilder.Entity().Property(x => x.IsPrimary); - modelBuilder.Entity().Property(x => x.Url).UseCollation(RepositoryModelConstraints.CaseSensitive); - - // ResourceType --------------------------------------------------------------- - modelBuilder.Entity().HasKey(x => x.FhirResourceType); - - modelBuilder.Entity().Property(x => x.FhirResourceType).HasConversion(); - modelBuilder.Entity().Property(x => x.Name).HasMaxLength(RepositoryModelConstraints.FhirResourceNameMaxLength); - - modelBuilder.Entity().HasData( - Enum.GetValues(typeof(FhirResourceTypeId)) - .Cast() - .Select(e => new ResourceType(e, e.ToString()))); - - // HttpVerb ----------------------------------------------------------------- - modelBuilder.Entity().HasKey(x => x.HttpVerbId); - - modelBuilder.Entity().Property(x => x.HttpVerbId).HasConversion(); - modelBuilder.Entity().Property(x => x.Name).HasMaxLength(RepositoryModelConstraints.CodeMaxLength); - - modelBuilder.Entity().HasData( - Enum.GetValues(typeof(HttpVerbId)) - .Cast() - .Select(e => new HttpVerb(e, e.ToString()))); - - // PublicationStatus -------------------------------------------------------- - modelBuilder.Entity().HasKey(x => x.PublicationStatusId); - - modelBuilder.Entity().Property(x => x.PublicationStatusId).HasConversion(); - modelBuilder.Entity().Property(x => x.Name).HasMaxLength(RepositoryModelConstraints.CodeMaxLength); - - modelBuilder.Entity().HasData( - Enum.GetValues(typeof(PublicationStatusId)) - .Cast() - .Select(e => new PublicationStatus(e, e.ToString()))); - - // Comparator --------------------------------------------------------------- - modelBuilder.Entity().HasKey(x => x.SearchComparatorId); - - modelBuilder.Entity().Property(x => x.SearchComparatorId).HasConversion(); - modelBuilder.Entity().Property(x => x.Name).HasMaxLength(RepositoryModelConstraints.CodeMaxLength); - - modelBuilder.Entity().HasData( - Enum.GetValues(typeof(SearchComparatorId)) - .Cast() - .Select(e => new Comparator(e, e.ToString()))); - - // SearchModifierCode --------------------------------------------------------------- - modelBuilder.Entity().HasKey(x => x.SearchModifierCodeId); - - modelBuilder.Entity().Property(x => x.SearchModifierCodeId).HasConversion(); - modelBuilder.Entity().Property(x => x.Name).HasMaxLength(RepositoryModelConstraints.CodeMaxLength); - - modelBuilder.Entity().HasData( - Enum.GetValues(typeof(SearchModifierCodeId)) - .Cast() - .Select(e => new SearchModifierCode(e, e.ToString()))); - - // SearchParameterStore ------------------------------------------------------ - modelBuilder.ApplyConfiguration(new SearchParameterStoreJsonCompressionConversion()); - - modelBuilder.Entity().HasKey(x => x.SearchParameterStoreId); - modelBuilder.Entity().HasAlternateKey(x => x.ResourceId); - modelBuilder.Entity().HasIndex(x => x.VersionId); - modelBuilder.Entity().HasIndex(x => x.Code); - - modelBuilder.Entity().Property(x => x.ResourceId) - .UseCollation(RepositoryModelConstraints.CaseSensitive) - .HasMaxLength(RepositoryModelConstraints.FhirIdMaxLength); - modelBuilder.Entity().Property(x => x.VersionId).HasMaxLength(RepositoryModelConstraints.FhirIdMaxLength); - modelBuilder.Entity().Property(x => x.IsCurrent); - modelBuilder.Entity().Property(x => x.IsDeleted); - modelBuilder.Entity().Property(x => x.IsIndexed); - modelBuilder.Entity().Property(x => x.Name).HasMaxLength(RepositoryModelConstraints.CodeMaxLength); - modelBuilder.Entity().Property(x => x.Status).HasConversion(); - modelBuilder.Entity().Property(x => x.Url); - modelBuilder.Entity().Property(x => x.Code).HasMaxLength(RepositoryModelConstraints.CodeMaxLength); - modelBuilder.Entity().Property(x => x.Type); - modelBuilder.Entity().Property(x => x.Expression); - modelBuilder.Entity().Property(x => x.MultipleOr); - modelBuilder.Entity().Property(x => x.MultipleAnd); - modelBuilder.Entity().Property(x => x.Chain); - modelBuilder.Entity().Property(x => x.Json); - modelBuilder.Entity().Property(x => x.LastUpdated).HasPrecision(RepositoryModelConstraints.TimestampPrecision); - modelBuilder.Entity().Property(x => x.RowVersion).IsConcurrencyToken(); - - - modelBuilder.Entity() - .HasMany(x => x.ComparatorList) - .WithOne(x => x.SearchParameterStore) - .HasForeignKey(x => x.SearchParameterStoreId); + // EntityTypeConfiguration ------------------------------------------------------------------------------------- + + //modelBuilder.UseCollation(RepositoryModelConstraints.CaseInsensitive); + modelBuilder.ApplyConfiguration(new ResourceStoreJsonCompressionConversion()); + modelBuilder.ApplyConfiguration(new SearchParameterStoreJsonCompressionConversion()); - modelBuilder.Entity() - .HasMany(x => x.BaseList) - .WithOne(x => x.SearchParameterStore) - .HasForeignKey(x => x.SearchParameterStoreId); - - modelBuilder.Entity() - .HasMany(x => x.TargetList) - .WithOne(x => x.SearchParameterStore) - .HasForeignKey(x => x.SearchParameterStoreId); - - modelBuilder.Entity() - .HasMany(x => x.ModifierList) - .WithOne(x => x.SearchParameterStore) - .HasForeignKey(x => x.SearchParameterStoreId); - - modelBuilder.Entity() - .HasMany(x => x.ComponentList) - .WithOne(x => x.SearchParameterStore) - .HasForeignKey(x => x.SearchParameterStoreId); - - modelBuilder.Entity().HasData(Seed.SearchParameterSeed.Get()); - - // SearchParameterStoreComparator --------------------------------------------------------------- - modelBuilder.Entity().HasKey(x => x.SearchParameterStoreComparatorId); - modelBuilder.Entity().HasIndex(x => x.SearchParameterStoreId); - - modelBuilder.Entity().Property(x => x.SearchParameterStoreId); - modelBuilder.Entity().Property(x => x.SearchComparatorId).HasConversion(); - modelBuilder.Entity().HasData(Seed.SearchParameterStoreComparatorSeed.Get()); - - // SearchParameterStoreResourceTypeBase --------------------------------------------------------------- - modelBuilder.Entity().HasKey(x => x.SearchParameterStoreResourceTypeBaseId); - modelBuilder.Entity().HasIndex(x => x.SearchParameterStoreId); - - modelBuilder.Entity().Property(x => x.SearchParameterStoreId); - modelBuilder.Entity().Property(x => x.ResourceType).HasConversion(); - modelBuilder.Entity().HasData(Seed.SearchParameterStoreResourceTypeBaseSeed.Get()); - - // SearchParameterStoreResourceTypeTarget --------------------------------------------------------------- - modelBuilder.Entity().HasKey(x => x.SearchParameterStoreResourceTypeTargetId); - modelBuilder.Entity().HasIndex(x => x.SearchParameterStoreId); - - modelBuilder.Entity().Property(x => x.SearchParameterStoreId); - modelBuilder.Entity().Property(x => x.ResourceType).HasConversion(); - modelBuilder.Entity().HasData(Seed.SearchParameterStoreResourceTypeTargetSeed.Get()); - - // SearchParameterStoreSearchModifierCode --------------------------------------------------------------- - modelBuilder.Entity().HasKey(x => x.SearchParameterStoreSearchModifierCodeId); - modelBuilder.Entity().HasIndex(x => x.SearchParameterStoreId); - - modelBuilder.Entity().Property(x => x.SearchParameterStoreId); - modelBuilder.Entity().Property(x => x.SearchModifierCodeId).HasConversion(); - modelBuilder.Entity().HasData(Seed.SearchParameterStoreSearchModifierCodeSeed.Get()); - - // SearchParameterStoreComponent --------------------------------------------------------------- - modelBuilder.Entity().HasKey(x => x.SearchParameterStoreComponentId); - modelBuilder.Entity().HasIndex(x => x.SearchParameterStoreId); - - modelBuilder.Entity().Property(x => x.SearchParameterStoreId); - modelBuilder.Entity().Property(x => x.Definition); - modelBuilder.Entity().Property(x => x.Expression); - modelBuilder.Entity().HasData(Seed.SearchParameterStoreComponentSeed.Get()); + //Entity Configurations ---------------------------------------------------------------------------------------- + + modelBuilder.ApplyConfiguration(new ResourceStoreEntityConfig()); + + modelBuilder.ApplyConfiguration(new IndexStringEntityConfig()); + modelBuilder.ApplyConfiguration(new IndexDateTimeEntityConfig()); + modelBuilder.ApplyConfiguration(new IndexReferenceEntityConfig()); + modelBuilder.ApplyConfiguration(new IndexQuantityEntityConfig()); + modelBuilder.ApplyConfiguration(new IndexTokenEntityConfig()); + modelBuilder.ApplyConfiguration(new IndexUriEntityConfig()); + + modelBuilder.ApplyConfiguration(new ServiceBaseUrlEntityConfig()); + + modelBuilder.ApplyConfiguration(new ResourceTypeEntityConfig()); + modelBuilder.ApplyConfiguration(new HttpVerbEntityConfig()); + modelBuilder.ApplyConfiguration(new PublicationStatusEntityConfig()); + modelBuilder.ApplyConfiguration(new ComparatorEntityConfig()); + modelBuilder.ApplyConfiguration(new SearchModifierCodeEntityConfig()); + + modelBuilder.ApplyConfiguration(new SearchParameterStoreEntityConfig()); + modelBuilder.ApplyConfiguration(new SearchParameterStoreComparatorEntityConfig()); + modelBuilder.ApplyConfiguration(new SearchParameterStoreResourceTypeBaseEntityConfig()); + modelBuilder.ApplyConfiguration(new SearchParameterStoreResourceTypeTargetEntityConfig()); + modelBuilder.ApplyConfiguration(new SearchParameterStoreSearchModifierCodeEntityConfig()); + modelBuilder.ApplyConfiguration(new SearchParameterStoreComponentEntityConfig()); } - } - +} \ No newline at end of file