mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
fix junction indexes
This commit is contained in:
parent
998fb171d2
commit
e34de71281
11 changed files with 73 additions and 29 deletions
|
|
@ -18,7 +18,6 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Migrations\" />
|
||||
<Folder Include="wwwroot\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
namespace FilterLists.Api.Migrations
|
||||
{
|
||||
[DbContext(typeof(FilterListsDbContext))]
|
||||
[Migration("20180207235556_InitialReCreate")]
|
||||
partial class InitialReCreate
|
||||
[Migration("20180208145019_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
|
|
@ -97,6 +97,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|||
|
||||
b.HasKey("FilterListId", "LanguageId");
|
||||
|
||||
b.HasIndex("LanguageId", "FilterListId");
|
||||
|
||||
b.ToTable("filterlists_languages");
|
||||
});
|
||||
|
||||
|
|
@ -112,6 +114,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|||
|
||||
b.HasKey("FilterListId", "MaintainerId");
|
||||
|
||||
b.HasIndex("MaintainerId", "FilterListId");
|
||||
|
||||
b.ToTable("filterlists_maintainers");
|
||||
});
|
||||
|
||||
|
|
@ -127,6 +131,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|||
|
||||
b.HasKey("ForkFilterListId", "UpstreamFilterListId");
|
||||
|
||||
b.HasIndex("UpstreamFilterListId", "ForkFilterListId");
|
||||
|
||||
b.ToTable("forks");
|
||||
});
|
||||
|
||||
|
|
@ -142,6 +148,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|||
|
||||
b.HasKey("MergeFilterListId", "UpstreamFilterListId");
|
||||
|
||||
b.HasIndex("UpstreamFilterListId", "MergeFilterListId");
|
||||
|
||||
b.ToTable("merges");
|
||||
});
|
||||
|
||||
|
|
@ -157,20 +165,24 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|||
|
||||
b.HasKey("SnapshotId", "RuleId");
|
||||
|
||||
b.HasIndex("RuleId", "SnapshotId");
|
||||
|
||||
b.ToTable("snapshots_rules");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FilterLists.Data.Entities.Junctions.SoftwareSyntax", b =>
|
||||
{
|
||||
b.Property<int>("SoftwareId");
|
||||
|
||||
b.Property<int>("SyntaxId");
|
||||
|
||||
b.Property<int>("SoftwareId");
|
||||
|
||||
b.Property<DateTime>("CreatedDateUtc")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TIMESTAMP");
|
||||
|
||||
b.HasKey("SoftwareId", "SyntaxId");
|
||||
b.HasKey("SyntaxId", "SoftwareId");
|
||||
|
||||
b.HasIndex("SoftwareId", "SyntaxId");
|
||||
|
||||
b.ToTable("software_syntaxes");
|
||||
});
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
namespace FilterLists.Api.Migrations
|
||||
{
|
||||
public partial class InitialReCreate : Migration
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
|
@ -164,14 +164,14 @@ protected override void Up(MigrationBuilder migrationBuilder)
|
|||
name: "software_syntaxes",
|
||||
columns: table => new
|
||||
{
|
||||
SoftwareId = table.Column<int>(nullable: false),
|
||||
SyntaxId = table.Column<int>(nullable: false),
|
||||
SoftwareId = table.Column<int>(nullable: false),
|
||||
CreatedDateUtc = table.Column<DateTime>(type: "TIMESTAMP", nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_software_syntaxes", x => new { x.SoftwareId, x.SyntaxId });
|
||||
table.PrimaryKey("PK_software_syntaxes", x => new { x.SyntaxId, x.SoftwareId });
|
||||
table.ForeignKey(
|
||||
name: "FK_software_syntaxes_software_SoftwareId",
|
||||
column: x => x.SoftwareId,
|
||||
|
|
@ -348,10 +348,40 @@ protected override void Up(MigrationBuilder migrationBuilder)
|
|||
table: "filterlists",
|
||||
column: "SyntaxId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_filterlists_languages_LanguageId_FilterListId",
|
||||
table: "filterlists_languages",
|
||||
columns: new[] { "LanguageId", "FilterListId" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_filterlists_maintainers_MaintainerId_FilterListId",
|
||||
table: "filterlists_maintainers",
|
||||
columns: new[] { "MaintainerId", "FilterListId" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_forks_UpstreamFilterListId_ForkFilterListId",
|
||||
table: "forks",
|
||||
columns: new[] { "UpstreamFilterListId", "ForkFilterListId" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_merges_UpstreamFilterListId_MergeFilterListId",
|
||||
table: "merges",
|
||||
columns: new[] { "UpstreamFilterListId", "MergeFilterListId" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_snapshots_FilterListId",
|
||||
table: "snapshots",
|
||||
column: "FilterListId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_snapshots_rules_RuleId_SnapshotId",
|
||||
table: "snapshots_rules",
|
||||
columns: new[] { "RuleId", "SnapshotId" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_software_syntaxes_SoftwareId_SyntaxId",
|
||||
table: "software_syntaxes",
|
||||
columns: new[] { "SoftwareId", "SyntaxId" });
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
|
|
@ -96,6 +96,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
|
|||
|
||||
b.HasKey("FilterListId", "LanguageId");
|
||||
|
||||
b.HasIndex("LanguageId", "FilterListId");
|
||||
|
||||
b.ToTable("filterlists_languages");
|
||||
});
|
||||
|
||||
|
|
@ -111,6 +113,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
|
|||
|
||||
b.HasKey("FilterListId", "MaintainerId");
|
||||
|
||||
b.HasIndex("MaintainerId", "FilterListId");
|
||||
|
||||
b.ToTable("filterlists_maintainers");
|
||||
});
|
||||
|
||||
|
|
@ -126,6 +130,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
|
|||
|
||||
b.HasKey("ForkFilterListId", "UpstreamFilterListId");
|
||||
|
||||
b.HasIndex("UpstreamFilterListId", "ForkFilterListId");
|
||||
|
||||
b.ToTable("forks");
|
||||
});
|
||||
|
||||
|
|
@ -141,6 +147,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
|
|||
|
||||
b.HasKey("MergeFilterListId", "UpstreamFilterListId");
|
||||
|
||||
b.HasIndex("UpstreamFilterListId", "MergeFilterListId");
|
||||
|
||||
b.ToTable("merges");
|
||||
});
|
||||
|
||||
|
|
@ -156,20 +164,24 @@ protected override void BuildModel(ModelBuilder modelBuilder)
|
|||
|
||||
b.HasKey("SnapshotId", "RuleId");
|
||||
|
||||
b.HasIndex("RuleId", "SnapshotId");
|
||||
|
||||
b.ToTable("snapshots_rules");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FilterLists.Data.Entities.Junctions.SoftwareSyntax", b =>
|
||||
{
|
||||
b.Property<int>("SoftwareId");
|
||||
|
||||
b.Property<int>("SyntaxId");
|
||||
|
||||
b.Property<int>("SoftwareId");
|
||||
|
||||
b.Property<DateTime>("CreatedDateUtc")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TIMESTAMP");
|
||||
|
||||
b.HasKey("SoftwareId", "SyntaxId");
|
||||
b.HasKey("SyntaxId", "SoftwareId");
|
||||
|
||||
b.HasIndex("SoftwareId", "SyntaxId");
|
||||
|
||||
b.ToTable("software_syntaxes");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ public override void Configure(EntityTypeBuilder<FilterListLanguage> entityTypeB
|
|||
base.Configure(entityTypeBuilder);
|
||||
entityTypeBuilder.ToTable("filterlists_languages");
|
||||
entityTypeBuilder.HasKey(x => new {x.FilterListId, x.LanguageId});
|
||||
entityTypeBuilder.HasIndex(x => new {x.LanguageId, x.FilterListId});
|
||||
entityTypeBuilder.HasOne(x => x.FilterList)
|
||||
.WithMany(x => x.FilterListLanguages)
|
||||
.HasForeignKey(x => x.FilterListId);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ public override void Configure(EntityTypeBuilder<FilterListMaintainer> entityTyp
|
|||
base.Configure(entityTypeBuilder);
|
||||
entityTypeBuilder.ToTable("filterlists_maintainers");
|
||||
entityTypeBuilder.HasKey(x => new {x.FilterListId, x.MaintainerId});
|
||||
entityTypeBuilder.HasIndex(x => new {x.MaintainerId, x.FilterListId});
|
||||
entityTypeBuilder.HasOne(x => x.FilterList)
|
||||
.WithMany(x => x.FilterListMaintainers)
|
||||
.HasForeignKey(x => x.FilterListId);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ public override void Configure(EntityTypeBuilder<Fork> entityTypeBuilder)
|
|||
base.Configure(entityTypeBuilder);
|
||||
entityTypeBuilder.ToTable("forks");
|
||||
entityTypeBuilder.HasKey(x => new {x.ForkFilterListId, x.UpstreamFilterListId});
|
||||
entityTypeBuilder.HasIndex(x => new {x.UpstreamFilterListId, x.ForkFilterListId});
|
||||
entityTypeBuilder.HasOne(x => x.ForkFilterList)
|
||||
.WithMany(x => x.ForkFilterLists)
|
||||
.HasForeignKey(x => x.ForkFilterListId);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ public override void Configure(EntityTypeBuilder<Merge> entityTypeBuilder)
|
|||
base.Configure(entityTypeBuilder);
|
||||
entityTypeBuilder.ToTable("merges");
|
||||
entityTypeBuilder.HasKey(x => new {x.MergeFilterListId, x.UpstreamFilterListId});
|
||||
entityTypeBuilder.HasIndex(x => new {x.UpstreamFilterListId, x.MergeFilterListId});
|
||||
entityTypeBuilder.HasOne(x => x.MergeFilterList)
|
||||
.WithMany(x => x.MergeFilterLists)
|
||||
.HasForeignKey(x => x.MergeFilterListId);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ public override void Configure(EntityTypeBuilder<SnapshotRule> entityTypeBuilder
|
|||
base.Configure(entityTypeBuilder);
|
||||
entityTypeBuilder.ToTable("snapshots_rules");
|
||||
entityTypeBuilder.HasKey(x => new {x.SnapshotId, x.RuleId});
|
||||
entityTypeBuilder.HasIndex(x => new {x.RuleId, x.SnapshotId});
|
||||
entityTypeBuilder.HasOne(x => x.Snapshot)
|
||||
.WithMany(x => x.SnapshotRules)
|
||||
.HasForeignKey(x => x.SnapshotId);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ public override void Configure(EntityTypeBuilder<SoftwareSyntax> entityTypeBuild
|
|||
{
|
||||
base.Configure(entityTypeBuilder);
|
||||
entityTypeBuilder.ToTable("software_syntaxes");
|
||||
entityTypeBuilder.HasKey(x => new {x.SoftwareId, x.SyntaxId});
|
||||
entityTypeBuilder.HasKey(x => new {x.SyntaxId, x.SoftwareId});
|
||||
entityTypeBuilder.HasIndex(x => new {x.SoftwareId, x.SyntaxId});
|
||||
entityTypeBuilder.HasOne(x => x.Software)
|
||||
.WithMany(x => x.SoftwareSyntaxes)
|
||||
.HasForeignKey(x => x.SoftwareId);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
using System.Linq;
|
||||
using FilterLists.Data.Entities;
|
||||
using FilterLists.Data.Entities;
|
||||
using FilterLists.Data.Entities.Junctions;
|
||||
using FilterLists.Data.EntityTypeConfigurations;
|
||||
using FilterLists.Data.EntityTypeConfigurations.Junctions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
|
||||
namespace FilterLists.Data
|
||||
{
|
||||
|
|
@ -19,19 +17,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|||
base.OnModelCreating(modelBuilder);
|
||||
ApplyConfigurationsEntities(modelBuilder);
|
||||
ApplyConfigurationsJunctions(modelBuilder);
|
||||
SelectivelyOmitConventions(modelBuilder);
|
||||
}
|
||||
|
||||
//TODO: update when official API supported
|
||||
//https://github.com/aspnet/EntityFrameworkCore/issues/10855#issuecomment-363219253
|
||||
//https://github.com/aspnet/EntityFrameworkCore/issues/7605
|
||||
private static void SelectivelyOmitConventions(ModelBuilder modelBuilder)
|
||||
{
|
||||
((Model)modelBuilder.Model).ConventionDispatcher.StartBatch();
|
||||
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
|
||||
foreach (var index in entityType.GetIndexes().ToList())
|
||||
if (index.DeclaringEntityType.Name.Contains("Junctions"))
|
||||
entityType.RemoveIndex(index.Properties);
|
||||
}
|
||||
|
||||
#region Entities
|
||||
|
|
|
|||
Loading…
Reference in a new issue