diff --git a/services/FilterLists.sln.DotSettings b/services/FilterLists.sln.DotSettings index 887fbac59..a48e85f7f 100644 --- a/services/FilterLists.sln.DotSettings +++ b/services/FilterLists.sln.DotSettings @@ -10,4 +10,5 @@ CHOP_IF_LONG CHOP_IF_LONG CHOP_IF_LONG + True True \ No newline at end of file diff --git a/services/directory/src/FilterLists.Directory.Infrastructure.Migrations/Migrations/20200827015901_Initial.Designer.cs b/services/directory/src/FilterLists.Directory.Infrastructure.Migrations/Migrations/20200827114853_Initial.Designer.cs similarity index 92% rename from services/directory/src/FilterLists.Directory.Infrastructure.Migrations/Migrations/20200827015901_Initial.Designer.cs rename to services/directory/src/FilterLists.Directory.Infrastructure.Migrations/Migrations/20200827114853_Initial.Designer.cs index 07b9d8a1c..c1559dd8c 100644 --- a/services/directory/src/FilterLists.Directory.Infrastructure.Migrations/Migrations/20200827015901_Initial.Designer.cs +++ b/services/directory/src/FilterLists.Directory.Infrastructure.Migrations/Migrations/20200827114853_Initial.Designer.cs @@ -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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + b1.Property("FilterListId") .HasColumnType("integer"); - b1.Property("Position") + b1.Property("Primariness") + .HasColumnType("integer"); + + b1.Property("SegmentNumber") .HasColumnType("integer"); b1.Property("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("SegmentViewUrlFilterListId") - .HasColumnType("integer"); - - b2.Property("SegmentViewUrlPosition") - .HasColumnType("integer"); - - b2.Property("Position") - .HasColumnType("integer"); - - b2.Property("Url") - .IsRequired() - .HasColumnType("text"); - - b2.HasKey("SegmentViewUrlFilterListId", "SegmentViewUrlPosition", "Position"); - - b2.ToTable("FilterListSegmentViewUrlMirrors"); - - b2.WithOwner("SegmentViewUrl") - .HasForeignKey("SegmentViewUrlFilterListId", "SegmentViewUrlPosition"); - }); }); }); diff --git a/services/directory/src/FilterLists.Directory.Infrastructure.Migrations/Migrations/20200827015901_Initial.cs b/services/directory/src/FilterLists.Directory.Infrastructure.Migrations/Migrations/20200827114853_Initial.cs similarity index 91% rename from services/directory/src/FilterLists.Directory.Infrastructure.Migrations/Migrations/20200827015901_Initial.cs rename to services/directory/src/FilterLists.Directory.Infrastructure.Migrations/Migrations/20200827114853_Initial.cs index 5d0066e94..b9c6cb79c 100644 --- a/services/directory/src/FilterLists.Directory.Infrastructure.Migrations/Migrations/20200827015901_Initial.cs +++ b/services/directory/src/FilterLists.Directory.Infrastructure.Migrations/Migrations/20200827114853_Initial.cs @@ -222,25 +222,6 @@ protected override void Up(MigrationBuilder migrationBuilder) onDelete: ReferentialAction.Cascade); }); - migrationBuilder.CreateTable( - name: "FilterListSegmentViewUrls", - columns: table => new - { - Position = table.Column(nullable: false), - FilterListId = table.Column(nullable: false), - Url = table.Column(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(nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + SegmentNumber = table.Column(nullable: false), + Primariness = table.Column(nullable: false), + Url = table.Column(nullable: false), + FilterListId = table.Column(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(nullable: false), - SegmentViewUrlFilterListId = table.Column(nullable: false), - SegmentViewUrlPosition = table.Column(nullable: false), - Url = table.Column(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"); } diff --git a/services/directory/src/FilterLists.Directory.Infrastructure.Migrations/Migrations/QueryDbContextModelSnapshot.cs b/services/directory/src/FilterLists.Directory.Infrastructure.Migrations/Migrations/QueryDbContextModelSnapshot.cs index 2c9781271..44bfc8c54 100644 --- a/services/directory/src/FilterLists.Directory.Infrastructure.Migrations/Migrations/QueryDbContextModelSnapshot.cs +++ b/services/directory/src/FilterLists.Directory.Infrastructure.Migrations/Migrations/QueryDbContextModelSnapshot.cs @@ -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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + b1.Property("FilterListId") .HasColumnType("integer"); - b1.Property("Position") + b1.Property("Primariness") + .HasColumnType("integer"); + + b1.Property("SegmentNumber") .HasColumnType("integer"); b1.Property("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("SegmentViewUrlFilterListId") - .HasColumnType("integer"); - - b2.Property("SegmentViewUrlPosition") - .HasColumnType("integer"); - - b2.Property("Position") - .HasColumnType("integer"); - - b2.Property("Url") - .IsRequired() - .HasColumnType("text"); - - b2.HasKey("SegmentViewUrlFilterListId", "SegmentViewUrlPosition", "Position"); - - b2.ToTable("FilterListSegmentViewUrlMirrors"); - - b2.WithOwner("SegmentViewUrl") - .HasForeignKey("SegmentViewUrlFilterListId", "SegmentViewUrlPosition"); - }); }); }); diff --git a/services/directory/src/FilterLists.Directory.Infrastructure/Persistence/Queries/Entities/FilterList.cs b/services/directory/src/FilterLists.Directory.Infrastructure/Persistence/Queries/Entities/FilterList.cs index 2b73260fe..c17e79265 100644 --- a/services/directory/src/FilterLists.Directory.Infrastructure/Persistence/Queries/Entities/FilterList.cs +++ b/services/directory/src/FilterLists.Directory.Infrastructure/Persistence/Queries/Entities/FilterList.cs @@ -15,7 +15,7 @@ public class FilterList public IReadOnlyCollection FilterListSyntaxes { get; private set; } = new HashSet(); public IReadOnlyCollection FilterListLanguages { get; private set; } = new HashSet(); public IReadOnlyCollection FilterListTags { get; private set; } = new HashSet(); - public IReadOnlyCollection SegmentViewUrls { get; private set; } = new HashSet(); + public IReadOnlyCollection ViewUrls { get; private set; } = new HashSet(); 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 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(segmentViewUrlFilterListId); - o2.Property(segmentViewUrlPosition); - o2.Property(m => m.Position).ValueGeneratedNever(); - o2.HasKey( - segmentViewUrlFilterListId, - segmentViewUrlPosition, - nameof(FilterListSegmentViewUrlMirror.Position)); - }) - .HasDataJsonFile(); + o.ToTable(nameof(FilterListViewUrl) + "s"); + const string id = "Id"; + o.Property(id); + o.HasKey(id); + const string filterListId = nameof(FilterList) + id; + o.Property(filterListId); + o.HasIndex( + filterListId, + nameof(FilterListViewUrl.SegmentNumber), + nameof(FilterListViewUrl.Primariness)) + .IsUnique(); }) - .HasDataJsonFile(); + .HasDataJsonFile(); builder.HasDataJsonFile(); } } diff --git a/services/directory/src/FilterLists.Directory.Infrastructure/Persistence/Queries/Entities/FilterListSegmentViewUrl.cs b/services/directory/src/FilterLists.Directory.Infrastructure/Persistence/Queries/Entities/FilterListSegmentViewUrl.cs deleted file mode 100644 index 67aee4658..000000000 --- a/services/directory/src/FilterLists.Directory.Infrastructure/Persistence/Queries/Entities/FilterListSegmentViewUrl.cs +++ /dev/null @@ -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 Mirrors { get; private set; } = new HashSet(); - } -} \ No newline at end of file diff --git a/services/directory/src/FilterLists.Directory.Infrastructure/Persistence/Queries/Entities/FilterListSegmentViewUrlMirror.cs b/services/directory/src/FilterLists.Directory.Infrastructure/Persistence/Queries/Entities/FilterListSegmentViewUrlMirror.cs deleted file mode 100644 index 12f7b3543..000000000 --- a/services/directory/src/FilterLists.Directory.Infrastructure/Persistence/Queries/Entities/FilterListSegmentViewUrlMirror.cs +++ /dev/null @@ -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!; - } -} \ No newline at end of file diff --git a/services/directory/src/FilterLists.Directory.Infrastructure/Persistence/Queries/Entities/FilterListViewUrl.cs b/services/directory/src/FilterLists.Directory.Infrastructure/Persistence/Queries/Entities/FilterListViewUrl.cs new file mode 100644 index 000000000..ac3594c0e --- /dev/null +++ b/services/directory/src/FilterLists.Directory.Infrastructure/Persistence/Queries/Entities/FilterListViewUrl.cs @@ -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!; + } +} \ No newline at end of file