refactor(directory): ♻ simplify ViewUrl data model

This commit is contained in:
Collin M. Barrett 2020-08-27 06:44:06 -05:00
parent c49ccaafff
commit 7e6607a5ee
8 changed files with 93 additions and 154 deletions

View file

@ -10,4 +10,5 @@
<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/UserDictionary/Words/=Primariness/@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("20200827015901_Initial")]
[Migration("20200827114853_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -343,47 +343,35 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
.WithMany("FilterLists")
.HasForeignKey("LicenseId");
b.OwnsMany("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterListSegmentViewUrl", "SegmentViewUrls", b1 =>
b.OwnsMany("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterListViewUrl", "ViewUrls", b1 =>
{
b1.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b1.Property<int>("FilterListId")
.HasColumnType("integer");
b1.Property<int>("Position")
b1.Property<int>("Primariness")
.HasColumnType("integer");
b1.Property<int>("SegmentNumber")
.HasColumnType("integer");
b1.Property<string>("Url")
.IsRequired()
.HasColumnType("text");
b1.HasKey("FilterListId", "Position");
b1.HasKey("Id");
b1.ToTable("FilterListSegmentViewUrls");
b1.HasIndex("FilterListId", "SegmentNumber", "Primariness")
.IsUnique();
b1.WithOwner("FilterList")
b1.ToTable("FilterListViewUrls");
b1.WithOwner()
.HasForeignKey("FilterListId");
b1.OwnsMany("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterListSegmentViewUrlMirror", "Mirrors", b2 =>
{
b2.Property<int>("SegmentViewUrlFilterListId")
.HasColumnType("integer");
b2.Property<int>("SegmentViewUrlPosition")
.HasColumnType("integer");
b2.Property<int>("Position")
.HasColumnType("integer");
b2.Property<string>("Url")
.IsRequired()
.HasColumnType("text");
b2.HasKey("SegmentViewUrlFilterListId", "SegmentViewUrlPosition", "Position");
b2.ToTable("FilterListSegmentViewUrlMirrors");
b2.WithOwner("SegmentViewUrl")
.HasForeignKey("SegmentViewUrlFilterListId", "SegmentViewUrlPosition");
});
});
});

View file

@ -222,25 +222,6 @@ protected override void Up(MigrationBuilder migrationBuilder)
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "FilterListSegmentViewUrls",
columns: table => new
{
Position = table.Column<int>(nullable: false),
FilterListId = table.Column<int>(nullable: false),
Url = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_FilterListSegmentViewUrls", x => new { x.FilterListId, x.Position });
table.ForeignKey(
name: "FK_FilterListSegmentViewUrls_FilterLists_FilterListId",
column: x => x.FilterListId,
principalTable: "FilterLists",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "FilterListSyntaxes",
columns: table => new
@ -289,6 +270,28 @@ protected override void Up(MigrationBuilder migrationBuilder)
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "FilterListViewUrls",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
SegmentNumber = table.Column<int>(nullable: false),
Primariness = table.Column<int>(nullable: false),
Url = table.Column<string>(nullable: false),
FilterListId = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_FilterListViewUrls", x => x.Id);
table.ForeignKey(
name: "FK_FilterListViewUrls_FilterLists_FilterListId",
column: x => x.FilterListId,
principalTable: "FilterLists",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Forks",
columns: table => new
@ -337,26 +340,6 @@ protected override void Up(MigrationBuilder migrationBuilder)
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "FilterListSegmentViewUrlMirrors",
columns: table => new
{
Position = table.Column<int>(nullable: false),
SegmentViewUrlFilterListId = table.Column<int>(nullable: false),
SegmentViewUrlPosition = table.Column<int>(nullable: false),
Url = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_FilterListSegmentViewUrlMirrors", x => new { x.SegmentViewUrlFilterListId, x.SegmentViewUrlPosition, x.Position });
table.ForeignKey(
name: "FK_FilterListSegmentViewUrlMirrors_FilterListSegmentViewUrls_S~",
columns: x => new { x.SegmentViewUrlFilterListId, x.SegmentViewUrlPosition },
principalTable: "FilterListSegmentViewUrls",
principalColumns: new[] { "FilterListId", "Position" },
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Dependents_DependentFilterListId",
table: "Dependents",
@ -387,6 +370,12 @@ protected override void Up(MigrationBuilder migrationBuilder)
table: "FilterListTags",
column: "TagId");
migrationBuilder.CreateIndex(
name: "IX_FilterListViewUrls_FilterListId_SegmentNumber_Primariness",
table: "FilterListViewUrls",
columns: new[] { "FilterListId", "SegmentNumber", "Primariness" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Forks_ForkFilterListId",
table: "Forks",
@ -414,15 +403,15 @@ protected override void Down(MigrationBuilder migrationBuilder)
migrationBuilder.DropTable(
name: "FilterListMaintainers");
migrationBuilder.DropTable(
name: "FilterListSegmentViewUrlMirrors");
migrationBuilder.DropTable(
name: "FilterListSyntaxes");
migrationBuilder.DropTable(
name: "FilterListTags");
migrationBuilder.DropTable(
name: "FilterListViewUrls");
migrationBuilder.DropTable(
name: "Forks");
@ -439,10 +428,10 @@ protected override void Down(MigrationBuilder migrationBuilder)
name: "Maintainers");
migrationBuilder.DropTable(
name: "FilterListSegmentViewUrls");
name: "Tags");
migrationBuilder.DropTable(
name: "Tags");
name: "FilterLists");
migrationBuilder.DropTable(
name: "Software");
@ -450,9 +439,6 @@ protected override void Down(MigrationBuilder migrationBuilder)
migrationBuilder.DropTable(
name: "Syntaxes");
migrationBuilder.DropTable(
name: "FilterLists");
migrationBuilder.DropTable(
name: "Licenses");
}

View file

@ -341,47 +341,35 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.WithMany("FilterLists")
.HasForeignKey("LicenseId");
b.OwnsMany("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterListSegmentViewUrl", "SegmentViewUrls", b1 =>
b.OwnsMany("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterListViewUrl", "ViewUrls", b1 =>
{
b1.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b1.Property<int>("FilterListId")
.HasColumnType("integer");
b1.Property<int>("Position")
b1.Property<int>("Primariness")
.HasColumnType("integer");
b1.Property<int>("SegmentNumber")
.HasColumnType("integer");
b1.Property<string>("Url")
.IsRequired()
.HasColumnType("text");
b1.HasKey("FilterListId", "Position");
b1.HasKey("Id");
b1.ToTable("FilterListSegmentViewUrls");
b1.HasIndex("FilterListId", "SegmentNumber", "Primariness")
.IsUnique();
b1.WithOwner("FilterList")
b1.ToTable("FilterListViewUrls");
b1.WithOwner()
.HasForeignKey("FilterListId");
b1.OwnsMany("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterListSegmentViewUrlMirror", "Mirrors", b2 =>
{
b2.Property<int>("SegmentViewUrlFilterListId")
.HasColumnType("integer");
b2.Property<int>("SegmentViewUrlPosition")
.HasColumnType("integer");
b2.Property<int>("Position")
.HasColumnType("integer");
b2.Property<string>("Url")
.IsRequired()
.HasColumnType("text");
b2.HasKey("SegmentViewUrlFilterListId", "SegmentViewUrlPosition", "Position");
b2.ToTable("FilterListSegmentViewUrlMirrors");
b2.WithOwner("SegmentViewUrl")
.HasForeignKey("SegmentViewUrlFilterListId", "SegmentViewUrlPosition");
});
});
});

View file

@ -15,7 +15,7 @@ public class FilterList
public IReadOnlyCollection<FilterListSyntax> FilterListSyntaxes { get; private set; } = new HashSet<FilterListSyntax>();
public IReadOnlyCollection<FilterListLanguage> FilterListLanguages { get; private set; } = new HashSet<FilterListLanguage>();
public IReadOnlyCollection<FilterListTag> FilterListTags { get; private set; } = new HashSet<FilterListTag>();
public IReadOnlyCollection<FilterListSegmentViewUrl> SegmentViewUrls { get; private set; } = new HashSet<FilterListSegmentViewUrl>();
public IReadOnlyCollection<FilterListViewUrl> ViewUrls { get; private set; } = new HashSet<FilterListViewUrl>();
public Uri? HomeUrl { get; private set; }
public Uri? OnionUrl { get; private set; }
public Uri? PolicyUrl { get; private set; }
@ -39,33 +39,22 @@ internal class FilterListTypeConfiguration : IEntityTypeConfiguration<FilterList
public virtual void Configure(EntityTypeBuilder<FilterList> builder)
{
_ = builder ?? throw new ArgumentNullException(nameof(builder));
builder.OwnsMany(fl => fl.SegmentViewUrls,
o1 =>
builder.OwnsMany(fl => fl.ViewUrls,
o =>
{
o1.ToTable(nameof(FilterListSegmentViewUrl) + "s");
const string filterListId = nameof(FilterList) + "Id";
o1.HasKey(filterListId, nameof(FilterListSegmentViewUrl.Position));
o1.Property(u => u.Position).ValueGeneratedNever();
o1.OwnsMany(u => u.Mirrors,
o2 =>
{
o2.ToTable(nameof(FilterListSegmentViewUrlMirror) + "s");
const string segmentViewUrlFilterListId =
nameof(FilterListSegmentViewUrlMirror.SegmentViewUrl) + filterListId;
const string segmentViewUrlPosition =
nameof(FilterListSegmentViewUrlMirror.SegmentViewUrl) +
nameof(FilterListSegmentViewUrlMirror.Position);
o2.Property<int>(segmentViewUrlFilterListId);
o2.Property<int>(segmentViewUrlPosition);
o2.Property(m => m.Position).ValueGeneratedNever();
o2.HasKey(
segmentViewUrlFilterListId,
segmentViewUrlPosition,
nameof(FilterListSegmentViewUrlMirror.Position));
})
.HasDataJsonFile<FilterListSegmentViewUrlMirror>();
o.ToTable(nameof(FilterListViewUrl) + "s");
const string id = "Id";
o.Property<int>(id);
o.HasKey(id);
const string filterListId = nameof(FilterList) + id;
o.Property<int>(filterListId);
o.HasIndex(
filterListId,
nameof(FilterListViewUrl.SegmentNumber),
nameof(FilterListViewUrl.Primariness))
.IsUnique();
})
.HasDataJsonFile<FilterListSegmentViewUrl>();
.HasDataJsonFile<FilterListViewUrl>();
builder.HasDataJsonFile<FilterList>();
}
}

View file

@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities
{
public class FilterListSegmentViewUrl
{
public FilterList FilterList { get; private set; } = null!;
public int Position { get; private set; }
public Uri Url { get; private set; } = null!;
public IReadOnlyCollection<FilterListSegmentViewUrlMirror> Mirrors { get; private set; } = new HashSet<FilterListSegmentViewUrlMirror>();
}
}

View file

@ -1,11 +0,0 @@
using System;
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities
{
public class FilterListSegmentViewUrlMirror
{
public FilterListSegmentViewUrl SegmentViewUrl { get; private set; } = null!;
public int Position { get; private set; }
public Uri Url { get; private set; } = null!;
}
}

View file

@ -0,0 +1,11 @@
using System;
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities
{
public class FilterListViewUrl
{
public int SegmentNumber { get; private set; }
public int Primariness { get; private set; }
public Uri Url { get; private set; } = null!;
}
}