refactor(directory): ♻ ren owned ViewUrl entities

This commit is contained in:
Collin M. Barrett 2020-08-26 17:10:29 -05:00
parent 0d2903c147
commit 0e7d2ac058
6 changed files with 61 additions and 61 deletions

View file

@ -10,7 +10,7 @@
namespace FilterLists.Directory.Infrastructure.Migrations.Migrations
{
[DbContext(typeof(QueryDbContext))]
[Migration("20200826190733_Initial")]
[Migration("20200826221237_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -343,7 +343,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
.WithMany("FilterLists")
.HasForeignKey("LicenseId");
b.OwnsMany("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.SegmentViewUrl", "SegmentViewUrls", b1 =>
b.OwnsMany("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterListSegmentViewUrl", "SegmentViewUrls", b1 =>
{
b1.Property<int>("Id")
.ValueGeneratedOnAdd()
@ -365,12 +365,12 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
b1.HasIndex("FilterListId", "Position")
.IsUnique();
b1.ToTable("SegmentViewUrls");
b1.ToTable("FilterListSegmentViewUrls");
b1.WithOwner("FilterList")
.HasForeignKey("FilterListId");
b1.OwnsMany("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.SegmentViewUrlMirror", "SegmentViewUrlMirrors", b2 =>
b1.OwnsMany("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterListSegmentViewUrlMirror", "Mirrors", b2 =>
{
b2.Property<int>("Id")
.ValueGeneratedOnAdd()
@ -388,7 +388,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
b2.HasIndex("SegmentViewUrlId");
b2.ToTable("SegmentViewUrlMirrors");
b2.ToTable("FilterListSegmentViewUrlMirrors");
b2.WithOwner("SegmentViewUrl")
.HasForeignKey("SegmentViewUrlId");

View file

@ -222,6 +222,27 @@ protected override void Up(MigrationBuilder migrationBuilder)
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "FilterListSegmentViewUrls",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
FilterListId = table.Column<int>(nullable: false),
Position = table.Column<int>(nullable: false),
Url = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_FilterListSegmentViewUrls", x => x.Id);
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
@ -319,28 +340,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
});
migrationBuilder.CreateTable(
name: "SegmentViewUrls",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
FilterListId = table.Column<int>(nullable: false),
Position = table.Column<int>(nullable: false),
Url = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SegmentViewUrls", x => x.Id);
table.ForeignKey(
name: "FK_SegmentViewUrls_FilterLists_FilterListId",
column: x => x.FilterListId,
principalTable: "FilterLists",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "SegmentViewUrlMirrors",
name: "FilterListSegmentViewUrlMirrors",
columns: table => new
{
Id = table.Column<int>(nullable: false)
@ -350,11 +350,11 @@ protected override void Up(MigrationBuilder migrationBuilder)
},
constraints: table =>
{
table.PrimaryKey("PK_SegmentViewUrlMirrors", x => x.Id);
table.PrimaryKey("PK_FilterListSegmentViewUrlMirrors", x => x.Id);
table.ForeignKey(
name: "FK_SegmentViewUrlMirrors_SegmentViewUrls_SegmentViewUrlId",
name: "FK_FilterListSegmentViewUrlMirrors_FilterListSegmentViewUrls_S~",
column: x => x.SegmentViewUrlId,
principalTable: "SegmentViewUrls",
principalTable: "FilterListSegmentViewUrls",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
@ -379,6 +379,17 @@ protected override void Up(MigrationBuilder migrationBuilder)
table: "FilterLists",
column: "LicenseId");
migrationBuilder.CreateIndex(
name: "IX_FilterListSegmentViewUrlMirrors_SegmentViewUrlId",
table: "FilterListSegmentViewUrlMirrors",
column: "SegmentViewUrlId");
migrationBuilder.CreateIndex(
name: "IX_FilterListSegmentViewUrls_FilterListId_Position",
table: "FilterListSegmentViewUrls",
columns: new[] { "FilterListId", "Position" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_FilterListSyntaxes_SyntaxId",
table: "FilterListSyntaxes",
@ -399,17 +410,6 @@ protected override void Up(MigrationBuilder migrationBuilder)
table: "Merges",
column: "IncludesFilterListId");
migrationBuilder.CreateIndex(
name: "IX_SegmentViewUrlMirrors_SegmentViewUrlId",
table: "SegmentViewUrlMirrors",
column: "SegmentViewUrlId");
migrationBuilder.CreateIndex(
name: "IX_SegmentViewUrls_FilterListId_Position",
table: "SegmentViewUrls",
columns: new[] { "FilterListId", "Position" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_SoftwareSyntaxes_SyntaxId",
table: "SoftwareSyntaxes",
@ -427,6 +427,9 @@ protected override void Down(MigrationBuilder migrationBuilder)
migrationBuilder.DropTable(
name: "FilterListMaintainers");
migrationBuilder.DropTable(
name: "FilterListSegmentViewUrlMirrors");
migrationBuilder.DropTable(
name: "FilterListSyntaxes");
@ -439,9 +442,6 @@ protected override void Down(MigrationBuilder migrationBuilder)
migrationBuilder.DropTable(
name: "Merges");
migrationBuilder.DropTable(
name: "SegmentViewUrlMirrors");
migrationBuilder.DropTable(
name: "SoftwareSyntaxes");
@ -452,10 +452,10 @@ protected override void Down(MigrationBuilder migrationBuilder)
name: "Maintainers");
migrationBuilder.DropTable(
name: "Tags");
name: "FilterListSegmentViewUrls");
migrationBuilder.DropTable(
name: "SegmentViewUrls");
name: "Tags");
migrationBuilder.DropTable(
name: "Software");

View file

@ -341,7 +341,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.WithMany("FilterLists")
.HasForeignKey("LicenseId");
b.OwnsMany("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.SegmentViewUrl", "SegmentViewUrls", b1 =>
b.OwnsMany("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterListSegmentViewUrl", "SegmentViewUrls", b1 =>
{
b1.Property<int>("Id")
.ValueGeneratedOnAdd()
@ -363,12 +363,12 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b1.HasIndex("FilterListId", "Position")
.IsUnique();
b1.ToTable("SegmentViewUrls");
b1.ToTable("FilterListSegmentViewUrls");
b1.WithOwner("FilterList")
.HasForeignKey("FilterListId");
b1.OwnsMany("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.SegmentViewUrlMirror", "SegmentViewUrlMirrors", b2 =>
b1.OwnsMany("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterListSegmentViewUrlMirror", "Mirrors", b2 =>
{
b2.Property<int>("Id")
.ValueGeneratedOnAdd()
@ -386,7 +386,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b2.HasIndex("SegmentViewUrlId");
b2.ToTable("SegmentViewUrlMirrors");
b2.ToTable("FilterListSegmentViewUrlMirrors");
b2.WithOwner("SegmentViewUrl")
.HasForeignKey("SegmentViewUrlId");

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<SegmentViewUrl> SegmentViewUrls { get; private set; } = new HashSet<SegmentViewUrl>();
public IReadOnlyCollection<FilterListSegmentViewUrl> SegmentViewUrls { get; private set; } = new HashSet<FilterListSegmentViewUrl>();
public Uri? HomeUrl { get; private set; }
public Uri? OnionUrl { get; private set; }
public Uri? PolicyUrl { get; private set; }
@ -42,19 +42,19 @@ public virtual void Configure(EntityTypeBuilder<FilterList> builder)
builder.OwnsMany(fl => fl.SegmentViewUrls,
o =>
{
o.ToTable(nameof(SegmentViewUrl) + "s");
o.ToTable(nameof(FilterListSegmentViewUrl) + "s");
o.HasKey("Id");
o.HasIndex(nameof(FilterList) + "Id", nameof(SegmentViewUrl.Position)).IsUnique();
o.OwnsMany(p => p.SegmentViewUrlMirrors,
o.HasIndex(nameof(FilterList) + "Id", nameof(FilterListSegmentViewUrl.Position)).IsUnique();
o.OwnsMany(p => p.Mirrors,
m =>
{
m.ToTable(nameof(SegmentViewUrlMirror) + "s");
m.ToTable(nameof(FilterListSegmentViewUrlMirror) + "s");
m.Property<int>("Id");
m.HasKey("Id");
})
.HasDataJsonFile<SegmentViewUrlMirror>();
.HasDataJsonFile<FilterListSegmentViewUrlMirror>();
})
.HasDataJsonFile<SegmentViewUrl>();
.HasDataJsonFile<FilterListSegmentViewUrl>();
builder.HasDataJsonFile<FilterList>();
}
}

View file

@ -3,11 +3,11 @@
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities
{
public class SegmentViewUrl
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<SegmentViewUrlMirror> SegmentViewUrlMirrors { get; private set; } = new HashSet<SegmentViewUrlMirror>();
public IReadOnlyCollection<FilterListSegmentViewUrlMirror> Mirrors { get; private set; } = new HashSet<FilterListSegmentViewUrlMirror>();
}
}

View file

@ -2,9 +2,9 @@
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities
{
public class SegmentViewUrlMirror
public class FilterListSegmentViewUrlMirror
{
public SegmentViewUrl SegmentViewUrl { get; private set; } = null!;
public FilterListSegmentViewUrl SegmentViewUrl { get; private set; } = null!;
public Uri Url { get; private set; } = null!;
}
}