refactor(directory): ♻ include explicit key props, flip-flop self-referencing many-to-many

This commit is contained in:
Collin M. Barrett 2020-08-25 16:15:27 -05:00
parent 60d1713a94
commit 1a7dac7af1
15 changed files with 61 additions and 79 deletions

View file

@ -1,11 +1,12 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml"
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_EMBEDDED_STATEMENT_ON_SAME_LINE/@EntryValue">NEVER</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_AFTER_DECLARATION_LPAR/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_CHAINED_BINARY_EXPRESSIONS/@EntryValue">CHOP_IF_LONG</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_CHAINED_METHOD_CALLS/@EntryValue">CHOP_IF_LONG</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_PARAMETERS_STYLE/@EntryValue">CHOP_IF_LONG</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Syntaxes/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View file

@ -10,7 +10,7 @@
namespace FilterLists.Directory.Infrastructure.Migrations.Migrations
{
[DbContext(typeof(QueryDbContext))]
[Migration("20200825102124_Initial")]
[Migration("20200825210326_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -371,13 +371,13 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
modelBuilder.Entity("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.Dependent", b =>
{
b.HasOne("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterList", "DependencyFilterList")
.WithMany("DependencyFilterLists")
.WithMany("DependentFilterLists")
.HasForeignKey("DependencyFilterListId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterList", "DependentFilterList")
.WithMany("DependentFilterLists")
.WithMany("DependencyFilterLists")
.HasForeignKey("DependentFilterListId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@ -453,13 +453,13 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
modelBuilder.Entity("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.Fork", b =>
{
b.HasOne("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterList", "ForkFilterList")
.WithMany("ForkFilterLists")
.WithMany("UpstreamFilterLists")
.HasForeignKey("ForkFilterListId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterList", "UpstreamFilterList")
.WithMany("UpstreamFilterLists")
.WithMany("ForkFilterLists")
.HasForeignKey("UpstreamFilterListId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@ -468,13 +468,13 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
modelBuilder.Entity("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.Merge", b =>
{
b.HasOne("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterList", "IncludedInFilterList")
.WithMany("IncludedInFilterLists")
.WithMany("IncludesFilterLists")
.HasForeignKey("IncludedInFilterListId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterList", "IncludesFilterList")
.WithMany("IncludesFilterLists")
.WithMany("IncludedInFilterLists")
.HasForeignKey("IncludesFilterListId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

View file

@ -369,13 +369,13 @@ protected override void BuildModel(ModelBuilder modelBuilder)
modelBuilder.Entity("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.Dependent", b =>
{
b.HasOne("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterList", "DependencyFilterList")
.WithMany("DependencyFilterLists")
.WithMany("DependentFilterLists")
.HasForeignKey("DependencyFilterListId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterList", "DependentFilterList")
.WithMany("DependentFilterLists")
.WithMany("DependencyFilterLists")
.HasForeignKey("DependentFilterListId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@ -451,13 +451,13 @@ protected override void BuildModel(ModelBuilder modelBuilder)
modelBuilder.Entity("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.Fork", b =>
{
b.HasOne("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterList", "ForkFilterList")
.WithMany("ForkFilterLists")
.WithMany("UpstreamFilterLists")
.HasForeignKey("ForkFilterListId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterList", "UpstreamFilterList")
.WithMany("UpstreamFilterLists")
.WithMany("ForkFilterLists")
.HasForeignKey("UpstreamFilterListId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@ -466,13 +466,13 @@ protected override void BuildModel(ModelBuilder modelBuilder)
modelBuilder.Entity("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.Merge", b =>
{
b.HasOne("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterList", "IncludedInFilterList")
.WithMany("IncludedInFilterLists")
.WithMany("IncludesFilterLists")
.HasForeignKey("IncludedInFilterListId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterList", "IncludesFilterList")
.WithMany("IncludesFilterLists")
.WithMany("IncludedInFilterLists")
.HasForeignKey("IncludesFilterListId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

View file

@ -8,7 +8,9 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Local")]
public class Dependent
{
public int DependencyFilterListId { get; private set; }
public FilterList DependencyFilterList { get; private set; } = null!;
public int DependentFilterListId { get; private set; }
public FilterList DependentFilterList { get; private set; } = null!;
}
@ -20,17 +22,13 @@ public virtual void Configure(EntityTypeBuilder<Dependent> builder)
builder.ToTable(nameof(Dependent) + "s");
const string dependencyFilterListId = nameof(Dependent.DependencyFilterList) + "Id";
const string dependentFilterListId = nameof(Dependent.DependentFilterList) + "Id";
builder.Property<int>(dependencyFilterListId);
builder.Property<int>(dependentFilterListId);
builder.HasKey(dependencyFilterListId, dependentFilterListId);
builder.HasKey(d => new {d.DependencyFilterListId, d.DependentFilterListId});
builder.HasOne(d => d.DependencyFilterList)
.WithMany(f => f.DependencyFilterLists)
.HasForeignKey(dependencyFilterListId);
.WithMany(fl => fl.DependentFilterLists)
.HasForeignKey(d => d.DependencyFilterListId);
builder.HasOne(d => d.DependentFilterList)
.WithMany(f => f.DependentFilterLists)
.HasForeignKey(dependentFilterListId);
.WithMany(fl => fl.DependencyFilterLists)
.HasForeignKey(d => d.DependentFilterListId);
}
}
}

View file

@ -10,6 +10,7 @@ public class FilterList
public int Id { get; private set; }
public string Name { get; private set; } = null!;
public string? Description { get; private set; }
public int? LicenseId { get; private set; }
public License? License { get; private set; }
public IReadOnlyCollection<FilterListSyntax> FilterListSyntaxes { get; private set; } = new HashSet<FilterListSyntax>();
public IReadOnlyCollection<FilterListLanguage> FilterListLanguages { get; private set; } = new HashSet<FilterListLanguage>();

View file

@ -8,7 +8,9 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Local")]
public class FilterListLanguage
{
public int FilterListId { get; private set; }
public FilterList FilterList { get; private set; } = null!;
public string LanguageIso6391 { get; private set; } = null!;
public Language Language { get; private set; } = null!;
}
@ -20,11 +22,7 @@ public virtual void Configure(EntityTypeBuilder<FilterListLanguage> builder)
builder.ToTable(nameof(FilterListLanguage) + "s");
const string filterListId = nameof(FilterListLanguage.FilterList) + "Id";
const string languageId = nameof(Language) + nameof(Language.Iso6391);
builder.Property<int>(filterListId);
builder.Property<string>(languageId);
builder.HasKey(filterListId, languageId);
builder.HasKey(fll => new {fll.FilterListId, fll.LanguageIso6391});
}
}
}

View file

@ -8,7 +8,9 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Local")]
public class FilterListMaintainer
{
public int FilterListId { get; private set; }
public FilterList FilterList { get; private set; } = null!;
public int MaintainerId { get; private set; }
public Maintainer Maintainer { get; private set; } = null!;
}
@ -20,11 +22,7 @@ public virtual void Configure(EntityTypeBuilder<FilterListMaintainer> builder)
builder.ToTable(nameof(FilterListMaintainer) + "s");
const string filterListId = nameof(FilterListMaintainer.FilterList) + "Id";
const string maintainerId = nameof(FilterListMaintainer.Maintainer) + "Id";
builder.Property<int>(filterListId);
builder.Property<int>(maintainerId);
builder.HasKey(filterListId, maintainerId);
builder.HasKey(flm => new {flm.FilterListId, flm.MaintainerId});
}
}
}

View file

@ -8,7 +8,9 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Local")]
public class FilterListSyntax
{
public int FilterListId { get; private set; }
public FilterList FilterList { get; private set; } = null!;
public int SyntaxId { get; private set; }
public Syntax Syntax { get; private set; } = null!;
}
@ -17,14 +19,10 @@ internal class FilterListSyntaxTypeConfiguration : IEntityTypeConfiguration<Filt
public virtual void Configure(EntityTypeBuilder<FilterListSyntax> builder)
{
_ = builder ?? throw new ArgumentNullException(nameof(builder));
builder.ToTable(nameof(FilterListSyntax) + "es");
const string filterListId = nameof(FilterListSyntax.FilterList) + "Id";
const string syntaxId = nameof(FilterListSyntax.Syntax) + "Id";
builder.Property<int>(filterListId);
builder.Property<int>(syntaxId);
builder.HasKey(filterListId, syntaxId);
builder.HasKey(fls => new {fls.FilterListId, fls.SyntaxId});
}
}
}

View file

@ -8,7 +8,9 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Local")]
public class FilterListTag
{
public int FilterListId { get; private set; }
public FilterList FilterList { get; private set; } = null!;
public int TagId { get; private set; }
public Tag Tag { get; private set; } = null!;
}
@ -20,11 +22,7 @@ public virtual void Configure(EntityTypeBuilder<FilterListTag> builder)
builder.ToTable(nameof(FilterListTag) + "s");
const string filterListId = nameof(FilterListTag.FilterList) + "Id";
const string tagId = nameof(FilterListTag.Tag) + "Id";
builder.Property<int>(filterListId);
builder.Property<int>(tagId);
builder.HasKey(filterListId, tagId);
builder.HasKey(flt => new {flt.FilterListId, flt.TagId});
}
}
}

View file

@ -8,7 +8,9 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Local")]
public class Fork
{
public int UpstreamFilterListId { get; private set; }
public FilterList UpstreamFilterList { get; private set; } = null!;
public int ForkFilterListId { get; private set; }
public FilterList ForkFilterList { get; private set; } = null!;
}
@ -20,17 +22,13 @@ public virtual void Configure(EntityTypeBuilder<Fork> builder)
builder.ToTable(nameof(Fork) + "s");
const string upstreamFilterListId = nameof(Fork.UpstreamFilterList) + "Id";
const string forkFilterListId = nameof(Fork.ForkFilterList) + "Id";
builder.Property<int>(upstreamFilterListId);
builder.Property<int>(forkFilterListId);
builder.HasKey(upstreamFilterListId, forkFilterListId);
builder.HasKey(f => new {f.UpstreamFilterListId, f.ForkFilterListId});
builder.HasOne(f => f.UpstreamFilterList)
.WithMany(f => f.UpstreamFilterLists)
.HasForeignKey(upstreamFilterListId);
.WithMany(fl => fl.ForkFilterLists)
.HasForeignKey(f => f.UpstreamFilterListId);
builder.HasOne(f => f.ForkFilterList)
.WithMany(f => f.ForkFilterLists)
.HasForeignKey(forkFilterListId);
.WithMany(fl => fl.UpstreamFilterLists)
.HasForeignKey(f => f.ForkFilterListId);
}
}
}

View file

@ -8,7 +8,9 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Local")]
public class Merge
{
public int IncludedInFilterListId { get; set; }
public FilterList IncludedInFilterList { get; private set; } = null!;
public int IncludesFilterListId { get; set; }
public FilterList IncludesFilterList { get; private set; } = null!;
}
@ -20,17 +22,13 @@ public virtual void Configure(EntityTypeBuilder<Merge> builder)
builder.ToTable(nameof(Merge) + "s");
const string includedInFilterListId = nameof(Merge.IncludedInFilterList) + "Id";
const string includesFilterListId = nameof(Merge.IncludesFilterList) + "Id";
builder.Property<int>(includedInFilterListId);
builder.Property<int>(includesFilterListId);
builder.HasKey(includedInFilterListId, includesFilterListId);
builder.HasKey(m => new {m.IncludedInFilterListId, m.IncludesFilterListId});
builder.HasOne(m => m.IncludedInFilterList)
.WithMany(f => f.IncludedInFilterLists)
.HasForeignKey(includedInFilterListId);
.WithMany(fl => fl.IncludesFilterLists)
.HasForeignKey(m => m.IncludedInFilterListId);
builder.HasOne(m => m.IncludesFilterList)
.WithMany(f => f.IncludesFilterLists)
.HasForeignKey(includesFilterListId);
.WithMany(fl => fl.IncludedInFilterLists)
.HasForeignKey(m => m.IncludesFilterListId);
}
}
}

View file

@ -9,6 +9,8 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Local")]
public class SegmentViewUrl
{
public int Id { get; private set; }
public int FilterListId { get; set; }
public FilterList FilterList { get; private set; } = null!;
public int Position { get; private set; }
public Uri Url { get; private set; } = null!;
@ -23,11 +25,7 @@ public virtual void Configure(EntityTypeBuilder<SegmentViewUrl> builder)
builder.ToTable(nameof(SegmentViewUrl) + "s");
const string segmentViewUrlId = "Id";
builder.Property<int>(segmentViewUrlId);
builder.HasKey(segmentViewUrlId);
builder.HasIndex(nameof(FilterList) + "Id", nameof(SegmentViewUrl.Position))
builder.HasIndex(s => new {s.FilterListId, s.Position})
.IsUnique();
}
}

View file

@ -8,6 +8,8 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Local")]
public class SegmentViewUrlMirror
{
public int Id { get; private set; }
public int SegmentViewUrlId { get; private set; }
public SegmentViewUrl SegmentViewUrl { get; private set; } = null!;
public Uri Url { get; private set; } = null!;
}
@ -19,10 +21,6 @@ public virtual void Configure(EntityTypeBuilder<SegmentViewUrlMirror> builder)
_ = builder ?? throw new ArgumentNullException(nameof(builder));
builder.ToTable(nameof(SegmentViewUrlMirror) + "s");
const string segmentViewUrlMirrorId = "Id";
builder.Property<int>(segmentViewUrlMirrorId);
builder.HasKey(segmentViewUrlMirrorId);
}
}
}

View file

@ -8,7 +8,9 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Local")]
public class SoftwareSyntax
{
public int SoftwareId { get; private set; }
public Software Software { get; private set; } = null!;
public int SyntaxId { get; private set; }
public Syntax Syntax { get; private set; } = null!;
}
@ -20,11 +22,7 @@ public virtual void Configure(EntityTypeBuilder<SoftwareSyntax> builder)
builder.ToTable(nameof(SoftwareSyntax) + "es");
const string softwareId = nameof(SoftwareSyntax.Software) + "Id";
const string syntaxId = nameof(SoftwareSyntax.Syntax) + "Id";
builder.Property<int>(softwareId);
builder.Property<int>(syntaxId);
builder.HasKey(softwareId, syntaxId);
builder.HasKey(ss => new {ss.SoftwareId, ss.SyntaxId});
}
}
}