Skip to content

Commit f53cb0c

Browse files
Copilotlinkdotnet
andauthored
Address PR #485 review feedback: Add unique index on ExternalId, comprehensive tests, and fix test name (#486)
* Initial plan * Add unique index on ExternalId and rename migration test Co-authored-by: linkdotnet <26365461+linkdotnet@users.noreply.github.com> * Add comprehensive tests for MarkdownImportJob Co-authored-by: linkdotnet <26365461+linkdotnet@users.noreply.github.com> * Add filter to unique index to handle null values Co-authored-by: linkdotnet <26365461+linkdotnet@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: linkdotnet <26365461+linkdotnet@users.noreply.github.com>
1 parent f4f7956 commit f53cb0c

6 files changed

Lines changed: 753 additions & 1 deletion

File tree

src/LinkDotNet.Blog.Infrastructure/Migrations/20260125214130_AddUniqueIndexOnExternalId.Designer.cs

Lines changed: 287 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using Microsoft.EntityFrameworkCore.Migrations;
3+
4+
#nullable disable
5+
6+
namespace LinkDotNet.Blog.Infrastructure.Migrations;
7+
8+
/// <inheritdoc />
9+
public partial class AddUniqueIndexOnExternalId : Migration
10+
{
11+
/// <inheritdoc />
12+
protected override void Up(MigrationBuilder migrationBuilder)
13+
{
14+
ArgumentNullException.ThrowIfNull(migrationBuilder);
15+
16+
migrationBuilder.CreateIndex(
17+
name: "IX_BlogPosts_ExternalId",
18+
table: "BlogPosts",
19+
column: "ExternalId",
20+
unique: true,
21+
filter: "ExternalId IS NOT NULL");
22+
}
23+
24+
/// <inheritdoc />
25+
protected override void Down(MigrationBuilder migrationBuilder)
26+
{
27+
ArgumentNullException.ThrowIfNull(migrationBuilder);
28+
29+
migrationBuilder.DropIndex(
30+
name: "IX_BlogPosts_ExternalId",
31+
table: "BlogPosts");
32+
}
33+
}

src/LinkDotNet.Blog.Infrastructure/Migrations/BlogDbContextModelSnapshot.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ protected override void BuildModel(ModelBuilder modelBuilder)
7676

7777
b.HasKey("Id");
7878

79+
b.HasIndex("ExternalId")
80+
.IsUnique()
81+
.HasDatabaseName("IX_BlogPosts_ExternalId")
82+
.HasFilter("ExternalId IS NOT NULL");
83+
7984
b.HasIndex("IsPublished", "UpdatedDate")
8085
.IsDescending(false, true)
8186
.HasDatabaseName("IX_BlogPosts_IsPublished_UpdatedDate");

src/LinkDotNet.Blog.Infrastructure/Persistence/Sql/Mapping/BlogPostConfiguration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ public void Configure(EntityTypeBuilder<BlogPost> builder)
2424
builder.Property(x => x.AuthorName).HasMaxLength(256).IsRequired(false);
2525
builder.Property(x => x.ExternalId).HasMaxLength(256).IsRequired(false);
2626

27+
builder.HasIndex(x => x.ExternalId)
28+
.HasDatabaseName("IX_BlogPosts_ExternalId")
29+
.IsUnique()
30+
.HasFilter("ExternalId IS NOT NULL");
31+
2732
builder.HasIndex(x => new { x.IsPublished, x.UpdatedDate })
2833
.HasDatabaseName("IX_BlogPosts_IsPublished_UpdatedDate")
2934
.IsDescending(false, true);

0 commit comments

Comments
 (0)