Skip to content

Commit

Permalink
Fitering out NULL from unique index to allow multiple rows with NULL …
Browse files Browse the repository at this point in the history
…as a value
  • Loading branch information
efonsecab committed Apr 11, 2024
1 parent 20519ae commit 39a65fb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<VideoInfo>(entity =>
{
entity.HasIndex(e => e.YouTubeVideoId, "UI_VideoInfo_YouTubeVideoId")
.IsUnique()
.HasFilter("YouTubeVideoId IS NOT NULL");
entity.Property(e => e.ApplicationUserId).HasComment("Video Owner Id");
entity.Property(e => e.RowCreationDateTime).HasDefaultValueSql("GETUTCDATE()");
entity.Property(e => e.RowCreationUser).HasDefaultValueSql("'Unknown'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace FairPlayCombined.DataAccess.Models.FairPlayTubeSchema;

[Table("VideoInfo", Schema = "FairPlayTube")]
[Index("VideoId", Name = "UI_VideoInfo_VideoId", IsUnique = true)]
[Index("YouTubeVideoId", Name = "UI_VideoInfo_YouTubeVideoId", IsUnique = true)]
public partial class VideoInfo
{
[Key]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ CREATE UNIQUE INDEX [UI_VideoInfo_VideoId] ON [FairPlayTube].[VideoInfo] ([Video

GO

CREATE UNIQUE INDEX [UI_VideoInfo_YouTubeVideoId] ON [FairPlayTube].[VideoInfo] ([YouTubeVideoId])
CREATE UNIQUE INDEX [UI_VideoInfo_YouTubeVideoId] ON [FairPlayTube].[VideoInfo] ([YouTubeVideoId]) WHERE YouTubeVideoId IS NOT NULL

0 comments on commit 39a65fb

Please sign in to comment.