mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
refactor(directory): use natural composite keys for nested view url owned types
This commit is contained in:
parent
dee69478c7
commit
c49ccaafff
5 changed files with 48 additions and 67 deletions
|
|
@ -10,7 +10,7 @@
|
|||
namespace FilterLists.Directory.Infrastructure.Migrations.Migrations
|
||||
{
|
||||
[DbContext(typeof(QueryDbContext))]
|
||||
[Migration("20200826221237_Initial")]
|
||||
[Migration("20200827015901_Initial")]
|
||||
partial class Initial
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
|
|
@ -345,11 +345,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|||
|
||||
b.OwnsMany("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterListSegmentViewUrl", "SegmentViewUrls", b1 =>
|
||||
{
|
||||
b1.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||
|
||||
b1.Property<int>("FilterListId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
|
|
@ -360,10 +355,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b1.HasKey("Id");
|
||||
|
||||
b1.HasIndex("FilterListId", "Position")
|
||||
.IsUnique();
|
||||
b1.HasKey("FilterListId", "Position");
|
||||
|
||||
b1.ToTable("FilterListSegmentViewUrls");
|
||||
|
||||
|
|
@ -372,26 +364,25 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|||
|
||||
b1.OwnsMany("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterListSegmentViewUrlMirror", "Mirrors", b2 =>
|
||||
{
|
||||
b2.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||
b2.Property<int>("SegmentViewUrlFilterListId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b2.Property<int>("SegmentViewUrlId")
|
||||
b2.Property<int>("SegmentViewUrlPosition")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b2.Property<int>("Position")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b2.Property<string>("Url")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b2.HasKey("Id");
|
||||
|
||||
b2.HasIndex("SegmentViewUrlId");
|
||||
b2.HasKey("SegmentViewUrlFilterListId", "SegmentViewUrlPosition", "Position");
|
||||
|
||||
b2.ToTable("FilterListSegmentViewUrlMirrors");
|
||||
|
||||
b2.WithOwner("SegmentViewUrl")
|
||||
.HasForeignKey("SegmentViewUrlId");
|
||||
.HasForeignKey("SegmentViewUrlFilterListId", "SegmentViewUrlPosition");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -226,15 +226,13 @@ protected override void Up(MigrationBuilder migrationBuilder)
|
|||
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),
|
||||
FilterListId = table.Column<int>(nullable: false),
|
||||
Url = table.Column<string>(nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_FilterListSegmentViewUrls", x => x.Id);
|
||||
table.PrimaryKey("PK_FilterListSegmentViewUrls", x => new { x.FilterListId, x.Position });
|
||||
table.ForeignKey(
|
||||
name: "FK_FilterListSegmentViewUrls_FilterLists_FilterListId",
|
||||
column: x => x.FilterListId,
|
||||
|
|
@ -343,19 +341,19 @@ protected override void Up(MigrationBuilder migrationBuilder)
|
|||
name: "FilterListSegmentViewUrlMirrors",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
SegmentViewUrlId = table.Column<int>(nullable: false),
|
||||
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 => x.Id);
|
||||
table.PrimaryKey("PK_FilterListSegmentViewUrlMirrors", x => new { x.SegmentViewUrlFilterListId, x.SegmentViewUrlPosition, x.Position });
|
||||
table.ForeignKey(
|
||||
name: "FK_FilterListSegmentViewUrlMirrors_FilterListSegmentViewUrls_S~",
|
||||
column: x => x.SegmentViewUrlId,
|
||||
columns: x => new { x.SegmentViewUrlFilterListId, x.SegmentViewUrlPosition },
|
||||
principalTable: "FilterListSegmentViewUrls",
|
||||
principalColumn: "Id",
|
||||
principalColumns: new[] { "FilterListId", "Position" },
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
|
|
@ -379,17 +377,6 @@ 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",
|
||||
|
|
@ -343,11 +343,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
|
|||
|
||||
b.OwnsMany("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterListSegmentViewUrl", "SegmentViewUrls", b1 =>
|
||||
{
|
||||
b1.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||
|
||||
b1.Property<int>("FilterListId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
|
|
@ -358,10 +353,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
|
|||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b1.HasKey("Id");
|
||||
|
||||
b1.HasIndex("FilterListId", "Position")
|
||||
.IsUnique();
|
||||
b1.HasKey("FilterListId", "Position");
|
||||
|
||||
b1.ToTable("FilterListSegmentViewUrls");
|
||||
|
||||
|
|
@ -370,26 +362,25 @@ protected override void BuildModel(ModelBuilder modelBuilder)
|
|||
|
||||
b1.OwnsMany("FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.FilterListSegmentViewUrlMirror", "Mirrors", b2 =>
|
||||
{
|
||||
b2.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||
b2.Property<int>("SegmentViewUrlFilterListId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b2.Property<int>("SegmentViewUrlId")
|
||||
b2.Property<int>("SegmentViewUrlPosition")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b2.Property<int>("Position")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b2.Property<string>("Url")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b2.HasKey("Id");
|
||||
|
||||
b2.HasIndex("SegmentViewUrlId");
|
||||
b2.HasKey("SegmentViewUrlFilterListId", "SegmentViewUrlPosition", "Position");
|
||||
|
||||
b2.ToTable("FilterListSegmentViewUrlMirrors");
|
||||
|
||||
b2.WithOwner("SegmentViewUrl")
|
||||
.HasForeignKey("SegmentViewUrlId");
|
||||
.HasForeignKey("SegmentViewUrlFilterListId", "SegmentViewUrlPosition");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -40,17 +40,28 @@ public virtual void Configure(EntityTypeBuilder<FilterList> builder)
|
|||
{
|
||||
_ = builder ?? throw new ArgumentNullException(nameof(builder));
|
||||
builder.OwnsMany(fl => fl.SegmentViewUrls,
|
||||
o =>
|
||||
o1 =>
|
||||
{
|
||||
o.ToTable(nameof(FilterListSegmentViewUrl) + "s");
|
||||
o.HasKey("Id");
|
||||
o.HasIndex(nameof(FilterList) + "Id", nameof(FilterListSegmentViewUrl.Position)).IsUnique();
|
||||
o.OwnsMany(p => p.Mirrors,
|
||||
m =>
|
||||
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 =>
|
||||
{
|
||||
m.ToTable(nameof(FilterListSegmentViewUrlMirror) + "s");
|
||||
m.Property<int>("Id");
|
||||
m.HasKey("Id");
|
||||
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>();
|
||||
})
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ 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!;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue