refactor(dir): ♻️ tidy QueryDbContext

This commit is contained in:
Collin Barrett 2024-05-31 14:28:15 -05:00
parent 2dbbdd981e
commit 9bee48aa30
18 changed files with 134 additions and 80 deletions

View file

@ -27,6 +27,7 @@ public override Task<int> SaveChangesAsync(
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.UseCollation("Latin1_General_100_CI_AS_SC");
modelBuilder.ApplyConfigurationsFromAssembly(
GetType().Assembly,
type => type.Namespace == typeof(FilterListTypeConfiguration).Namespace);

View file

@ -5,10 +5,10 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record Dependent
{
public long DependencyFilterListId { get; init; }
public FilterList DependencyFilterList { get; init; } = default!;
public long DependentFilterListId { get; init; }
public FilterList DependentFilterList { get; init; } = default!;
public int DependencyFilterListId { get; init; }
public FilterList DependencyFilterList { get; init; } = null!;
public int DependentFilterListId { get; init; }
public FilterList DependentFilterList { get; init; } = null!;
}
internal class DependentTypeConfiguration : IEntityTypeConfiguration<Dependent>
@ -21,7 +21,8 @@ public virtual void Configure(EntityTypeBuilder<Dependent> builder)
.HasForeignKey(d => d.DependencyFilterListId);
builder.HasOne(d => d.DependentFilterList)
.WithMany(fl => fl.DependencyFilterLists)
.HasForeignKey(d => d.DependentFilterListId);
.HasForeignKey(d => d.DependentFilterListId)
.OnDelete(DeleteBehavior.NoAction);
builder.HasDataJsonFile<Dependent>();
}
}

View file

@ -1,6 +0,0 @@
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public abstract record Entity
{
public long Id { get; init; }
}

View file

@ -3,16 +3,17 @@
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record FilterList : Entity
public record FilterList
{
public string Name { get; init; } = default!;
public int Id { get; init; }
public string Name { get; init; } = null!;
public string? Description { get; init; }
public long LicenseId { get; init; }
public License License { get; init; } = default!;
public IEnumerable<FilterListSyntax> FilterListSyntaxes { get; init; } = new HashSet<FilterListSyntax>();
public IEnumerable<FilterListLanguage> FilterListLanguages { get; init; } = new HashSet<FilterListLanguage>();
public IEnumerable<FilterListTag> FilterListTags { get; init; } = new HashSet<FilterListTag>();
public IEnumerable<FilterListViewUrl> ViewUrls { get; init; } = new HashSet<FilterListViewUrl>();
public int LicenseId { get; init; }
public License License { get; init; } = null!;
public IEnumerable<FilterListSyntax> FilterListSyntaxes { get; init; } = new List<FilterListSyntax>();
public IEnumerable<FilterListLanguage> FilterListLanguages { get; init; } = new List<FilterListLanguage>();
public IEnumerable<FilterListTag> FilterListTags { get; init; } = new List<FilterListTag>();
public IEnumerable<FilterListViewUrl> ViewUrls { get; init; } = new List<FilterListViewUrl>();
public Uri? HomeUrl { get; init; }
public Uri? OnionUrl { get; init; }
public Uri? PolicyUrl { get; init; }
@ -22,19 +23,21 @@ public record FilterList : Entity
public Uri? ChatUrl { get; init; }
public string? EmailAddress { get; init; }
public Uri? DonateUrl { get; init; }
public IEnumerable<FilterListMaintainer> FilterListMaintainers { get; init; } = new HashSet<FilterListMaintainer>();
public IEnumerable<Fork> UpstreamFilterLists { get; init; } = new HashSet<Fork>();
public IEnumerable<Fork> ForkFilterLists { get; init; } = new HashSet<Fork>();
public IEnumerable<Merge> IncludedInFilterLists { get; init; } = new HashSet<Merge>();
public IEnumerable<Merge> IncludesFilterLists { get; init; } = new HashSet<Merge>();
public IEnumerable<Dependent> DependencyFilterLists { get; init; } = new HashSet<Dependent>();
public IEnumerable<Dependent> DependentFilterLists { get; init; } = new HashSet<Dependent>();
public IEnumerable<FilterListMaintainer> FilterListMaintainers { get; init; } = new List<FilterListMaintainer>();
public IEnumerable<Fork> UpstreamFilterLists { get; init; } = new List<Fork>();
public IEnumerable<Fork> ForkFilterLists { get; init; } = new List<Fork>();
public IEnumerable<Merge> IncludedInFilterLists { get; init; } = new List<Merge>();
public IEnumerable<Merge> IncludesFilterLists { get; init; } = new List<Merge>();
public IEnumerable<Dependent> DependencyFilterLists { get; init; } = new List<Dependent>();
public IEnumerable<Dependent> DependentFilterLists { get; init; } = new List<Dependent>();
}
internal class FilterListTypeConfiguration : IEntityTypeConfiguration<FilterList>
{
public virtual void Configure(EntityTypeBuilder<FilterList> builder)
{
builder.Property(f => f.Name)
.HasMaxLength(256);
builder.HasIndex(f => f.Name)
.IsUnique();
builder.Property(f => f.LicenseId)
@ -42,6 +45,24 @@ public virtual void Configure(EntityTypeBuilder<FilterList> builder)
builder.HasOne(f => f.License)
.WithMany(l => l.FilterLists)
.OnDelete(DeleteBehavior.Restrict);
builder.Property(f => f.HomeUrl)
.HasMaxLength(512);
builder.Property(f => f.OnionUrl)
.HasMaxLength(512);
builder.Property(f => f.PolicyUrl)
.HasMaxLength(512);
builder.Property(f => f.SubmissionUrl)
.HasMaxLength(512);
builder.Property(f => f.IssuesUrl)
.HasMaxLength(512);
builder.Property(f => f.ForumUrl)
.HasMaxLength(512);
builder.Property(f => f.ChatUrl)
.HasMaxLength(512);
builder.Property(f => f.EmailAddress)
.HasMaxLength(256);
builder.Property(f => f.DonateUrl)
.HasMaxLength(512);
builder.OwnsMany(
f => f.ViewUrls,
b =>
@ -50,6 +71,8 @@ public virtual void Configure(EntityTypeBuilder<FilterList> builder)
.HasDefaultValue(1);
b.Property(u => u.Primariness)
.HasDefaultValue(1);
b.Property(u => u.Url)
.HasMaxLength(512);
b.HasIndex(u => new { u.FilterListId, u.SegmentNumber, u.Primariness })
.IsUnique();
b.HasDataJsonFile<FilterListViewUrl>();

View file

@ -5,10 +5,10 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record FilterListLanguage
{
public long FilterListId { get; init; }
public FilterList FilterList { get; init; } = default!;
public long LanguageId { get; init; }
public Language Language { get; init; } = default!;
public int FilterListId { get; init; }
public FilterList FilterList { get; init; } = null!;
public short LanguageId { get; init; }
public Language Language { get; init; } = null!;
}
internal class FilterListLanguageTypeConfiguration : IEntityTypeConfiguration<FilterListLanguage>

View file

@ -5,10 +5,10 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record FilterListMaintainer
{
public long FilterListId { get; init; }
public FilterList FilterList { get; init; } = default!;
public long MaintainerId { get; init; }
public Maintainer Maintainer { get; init; } = default!;
public int FilterListId { get; init; }
public FilterList FilterList { get; init; } = null!;
public int MaintainerId { get; init; }
public Maintainer Maintainer { get; init; } = null!;
}
internal class FilterListMaintainerTypeConfiguration : IEntityTypeConfiguration<FilterListMaintainer>

View file

@ -5,10 +5,10 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record FilterListSyntax
{
public long FilterListId { get; init; }
public FilterList FilterList { get; init; } = default!;
public long SyntaxId { get; init; }
public Syntax Syntax { get; init; } = default!;
public int FilterListId { get; init; }
public FilterList FilterList { get; init; } = null!;
public short SyntaxId { get; init; }
public Syntax Syntax { get; init; } = null!;
}
internal class FilterListSyntaxTypeConfiguration : IEntityTypeConfiguration<FilterListSyntax>

View file

@ -5,10 +5,10 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record FilterListTag
{
public long FilterListId { get; init; }
public FilterList FilterList { get; init; } = default!;
public long TagId { get; init; }
public Tag Tag { get; init; } = default!;
public int FilterListId { get; init; }
public FilterList FilterList { get; init; } = null!;
public int TagId { get; init; }
public Tag Tag { get; init; } = null!;
}
internal class FilterListTagTypeConfiguration : IEntityTypeConfiguration<FilterListTag>

View file

@ -1,10 +1,11 @@
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record FilterListViewUrl : Entity
public record FilterListViewUrl
{
public long FilterListId { get; init; }
public FilterList FilterList { get; init; } = default!;
public int Id { get; init; }
public int FilterListId { get; init; }
public FilterList FilterList { get; init; } = null!;
public short SegmentNumber { get; init; }
public short Primariness { get; init; }
public Uri Url { get; init; } = default!;
public Uri Url { get; init; } = null!;
}

View file

@ -5,10 +5,10 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record Fork
{
public long UpstreamFilterListId { get; init; }
public FilterList UpstreamFilterList { get; init; } = default!;
public long ForkFilterListId { get; init; }
public FilterList ForkFilterList { get; init; } = default!;
public int UpstreamFilterListId { get; init; }
public FilterList UpstreamFilterList { get; init; } = null!;
public int ForkFilterListId { get; init; }
public FilterList ForkFilterList { get; init; } = null!;
}
internal class ForkTypeConfiguration : IEntityTypeConfiguration<Fork>
@ -21,7 +21,8 @@ public virtual void Configure(EntityTypeBuilder<Fork> builder)
.HasForeignKey(f => f.UpstreamFilterListId);
builder.HasOne(f => f.ForkFilterList)
.WithMany(fl => fl.UpstreamFilterLists)
.HasForeignKey(f => f.ForkFilterListId);
.HasForeignKey(f => f.ForkFilterListId)
.OnDelete(DeleteBehavior.NoAction);
builder.HasDataJsonFile<Fork>();
}
}

View file

@ -3,11 +3,12 @@
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record Language : Entity
public record Language
{
public string Iso6391 { get; init; } = default!;
public string Name { get; init; } = default!;
public IEnumerable<FilterListLanguage> FilterListLanguages { get; init; } = new HashSet<FilterListLanguage>();
public short Id { get; init; }
public string Iso6391 { get; init; } = null!;
public string Name { get; init; } = null!;
public IEnumerable<FilterListLanguage> FilterListLanguages { get; init; } = new List<FilterListLanguage>();
}
internal class LanguageTypeConfiguration : IEntityTypeConfiguration<Language>
@ -19,6 +20,8 @@ public virtual void Configure(EntityTypeBuilder<Language> builder)
.HasMaxLength(2);
builder.HasIndex(l => l.Iso6391)
.IsUnique();
builder.Property(l => l.Name)
.HasMaxLength(64);
builder.HasIndex(l => l.Name)
.IsUnique();
builder.HasDataJsonFile<Language>();

View file

@ -3,22 +3,27 @@
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record License : Entity
public record License
{
public string Name { get; init; } = default!;
public int Id { get; init; }
public string Name { get; init; } = null!;
public Uri? Url { get; init; }
public bool PermitsModification { get; init; }
public bool PermitsDistribution { get; init; }
public bool PermitsCommercialUse { get; init; }
public IEnumerable<FilterList> FilterLists { get; init; } = new HashSet<FilterList>();
public IEnumerable<FilterList> FilterLists { get; init; } = new List<FilterList>();
}
internal class LicenseTypeConfiguration : IEntityTypeConfiguration<License>
{
public virtual void Configure(EntityTypeBuilder<License> builder)
{
builder.Property(l => l.Name)
.HasMaxLength(64);
builder.HasIndex(l => l.Name)
.IsUnique();
builder.Property(l => l.Url)
.HasMaxLength(512);
builder.Property(l => l.PermitsModification)
.HasDefaultValue(false);
builder.Property(l => l.PermitsDistribution)

View file

@ -3,21 +3,30 @@
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record Maintainer : Entity
public record Maintainer
{
public string Name { get; init; } = default!;
public int Id { get; init; }
public string Name { get; init; } = null!;
public Uri? Url { get; init; }
public string? EmailAddress { get; init; }
public string? TwitterHandle { get; init; }
public IEnumerable<FilterListMaintainer> FilterListMaintainers { get; init; } = new HashSet<FilterListMaintainer>();
public IEnumerable<FilterListMaintainer> FilterListMaintainers { get; init; } = new List<FilterListMaintainer>();
}
internal class MaintainerTypeConfiguration : IEntityTypeConfiguration<Maintainer>
{
public virtual void Configure(EntityTypeBuilder<Maintainer> builder)
{
builder.Property(m => m.Name)
.HasMaxLength(64);
builder.HasIndex(m => m.Name)
.IsUnique();
builder.Property(m => m.Url)
.HasMaxLength(512);
builder.Property(m => m.EmailAddress)
.HasMaxLength(256);
builder.Property(m => m.TwitterHandle)
.HasMaxLength(32);
builder.HasDataJsonFile<Maintainer>();
}
}

View file

@ -5,10 +5,10 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record Merge
{
public long IncludedInFilterListId { get; init; }
public FilterList IncludedInFilterList { get; init; } = default!;
public long IncludesFilterListId { get; init; }
public FilterList IncludesFilterList { get; init; } = default!;
public int IncludedInFilterListId { get; init; }
public FilterList IncludedInFilterList { get; init; } = null!;
public int IncludesFilterListId { get; init; }
public FilterList IncludesFilterList { get; init; } = null!;
}
internal class MergeTypeConfiguration : IEntityTypeConfiguration<Merge>
@ -21,7 +21,8 @@ public virtual void Configure(EntityTypeBuilder<Merge> builder)
.HasForeignKey(m => m.IncludedInFilterListId);
builder.HasOne(m => m.IncludesFilterList)
.WithMany(fl => fl.IncludedInFilterLists)
.HasForeignKey(m => m.IncludesFilterListId);
.HasForeignKey(m => m.IncludesFilterListId)
.OnDelete(DeleteBehavior.NoAction);
builder.HasDataJsonFile<Merge>();
}
}

View file

@ -3,22 +3,29 @@
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record Software : Entity
public record Software
{
public string Name { get; init; } = default!;
public short Id { get; init; }
public string Name { get; init; } = null!;
public string? Description { get; init; }
public Uri? HomeUrl { get; init; }
public Uri? DownloadUrl { get; init; }
public bool SupportsAbpUrlScheme { get; init; }
public IEnumerable<SoftwareSyntax> SoftwareSyntaxes { get; init; } = new HashSet<SoftwareSyntax>();
public IEnumerable<SoftwareSyntax> SoftwareSyntaxes { get; init; } = new List<SoftwareSyntax>();
}
internal class SoftwareTypeConfiguration : IEntityTypeConfiguration<Software>
{
public virtual void Configure(EntityTypeBuilder<Software> builder)
{
builder.Property(s => s.Name)
.HasMaxLength(64);
builder.HasIndex(s => s.Name)
.IsUnique();
builder.Property(s => s.HomeUrl)
.HasMaxLength(512);
builder.Property(s => s.DownloadUrl)
.HasMaxLength(512);
builder.Property(s => s.SupportsAbpUrlScheme)
.HasDefaultValue(false);
builder.HasDataJsonFile<Software>();

View file

@ -5,10 +5,10 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record SoftwareSyntax
{
public long SoftwareId { get; init; }
public Software Software { get; init; } = default!;
public long SyntaxId { get; init; }
public Syntax Syntax { get; init; } = default!;
public short SoftwareId { get; init; }
public Software Software { get; init; } = null!;
public short SyntaxId { get; init; }
public Syntax Syntax { get; init; } = null!;
}
internal class SoftwareSyntaxTypeConfiguration : IEntityTypeConfiguration<SoftwareSyntax>

View file

@ -3,21 +3,26 @@
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record Syntax : Entity
public record Syntax
{
public string Name { get; init; } = default!;
public short Id { get; init; }
public string Name { get; init; } = null!;
public string? Description { get; init; }
public Uri? Url { get; init; }
public IEnumerable<FilterListSyntax> FilterListSyntaxes { get; init; } = new HashSet<FilterListSyntax>();
public IEnumerable<SoftwareSyntax> SoftwareSyntaxes { get; init; } = new HashSet<SoftwareSyntax>();
public IEnumerable<FilterListSyntax> FilterListSyntaxes { get; init; } = new List<FilterListSyntax>();
public IEnumerable<SoftwareSyntax> SoftwareSyntaxes { get; init; } = new List<SoftwareSyntax>();
}
internal class SyntaxTypeConfiguration : IEntityTypeConfiguration<Syntax>
{
public virtual void Configure(EntityTypeBuilder<Syntax> builder)
{
builder.Property(s => s.Name)
.HasMaxLength(64);
builder.HasIndex(s => s.Name)
.IsUnique();
builder.Property(s => s.Url)
.HasMaxLength(512);
builder.HasDataJsonFile<Syntax>();
}
}

View file

@ -3,17 +3,20 @@
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record Tag : Entity
public record Tag
{
public string Name { get; init; } = default!;
public int Id { get; init; }
public string Name { get; init; } = null!;
public string? Description { get; init; }
public IEnumerable<FilterListTag> FilterListTags { get; init; } = new HashSet<FilterListTag>();
public IEnumerable<FilterListTag> FilterListTags { get; init; } = new List<FilterListTag>();
}
internal class TagTypeConfiguration : IEntityTypeConfiguration<Tag>
{
public virtual void Configure(EntityTypeBuilder<Tag> builder)
{
builder.Property(t => t.Name)
.HasMaxLength(32);
builder.HasIndex(t => t.Name)
.IsUnique();
builder.HasDataJsonFile<Tag>();