add junction composite indices

This commit is contained in:
Collin M. Barrett 2018-02-06 10:19:11 -06:00
parent d0faa7ac8b
commit fa3b61cade
9 changed files with 646 additions and 0 deletions

View file

@ -0,0 +1,523 @@
// <auto-generated />
using FilterLists.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage;
using System;
namespace FilterLists.Api.Migrations
{
[DbContext(typeof(FilterListsDbContext))]
[Migration("20180206161803_AddJunctionCompositeIndices")]
partial class AddJunctionCompositeIndices
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn)
.HasAnnotation("ProductVersion", "2.0.1-rtm-125");
modelBuilder.Entity("FilterLists.Data.Entities.FilterList", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("SMALLINT UNSIGNED");
b.Property<DateTime>("CreatedDateUtc")
.ValueGeneratedOnAdd()
.HasColumnType("TIMESTAMP");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("DescriptionSourceUrl")
.HasColumnType("TEXT");
b.Property<DateTime?>("DiscontinuedDate");
b.Property<string>("DonateUrl")
.HasColumnType("TEXT");
b.Property<string>("EmailAddress")
.ValueGeneratedOnAdd()
.HasColumnType("VARCHAR(126)")
.HasDefaultValueSql("NULL");
b.Property<string>("ForumUrl")
.HasColumnType("TEXT");
b.Property<string>("HomeUrl")
.HasColumnType("TEXT");
b.Property<string>("IssuesUrl")
.HasColumnType("TEXT");
b.Property<int?>("LicenseId");
b.Property<DateTime>("ModifiedDateUtc")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("TIMESTAMP");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("VARCHAR(126)");
b.Property<string>("PolicyUrl")
.HasColumnType("TEXT");
b.Property<string>("SubmissionUrl")
.HasColumnType("TEXT");
b.Property<int?>("SyntaxId");
b.Property<string>("ViewUrl")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("LicenseId");
b.HasIndex("SyntaxId");
b.ToTable("filterlists");
});
modelBuilder.Entity("FilterLists.Data.Entities.Junctions.FilterListLanguage", b =>
{
b.Property<int>("FilterListId");
b.Property<int>("LanguageId");
b.Property<DateTime>("CreatedDateUtc")
.ValueGeneratedOnAdd()
.HasColumnType("TIMESTAMP");
b.HasKey("FilterListId", "LanguageId");
b.HasIndex("LanguageId");
b.HasIndex("FilterListId", "LanguageId")
.IsUnique();
b.ToTable("filterlists_languages");
});
modelBuilder.Entity("FilterLists.Data.Entities.Junctions.FilterListMaintainer", b =>
{
b.Property<int>("FilterListId");
b.Property<int>("MaintainerId");
b.Property<DateTime>("CreatedDateUtc")
.ValueGeneratedOnAdd()
.HasColumnType("TIMESTAMP");
b.HasKey("FilterListId", "MaintainerId");
b.HasIndex("MaintainerId");
b.HasIndex("FilterListId", "MaintainerId")
.IsUnique();
b.ToTable("filterlists_maintainers");
});
modelBuilder.Entity("FilterLists.Data.Entities.Junctions.Fork", b =>
{
b.Property<int>("ForkFilterListId");
b.Property<int>("UpstreamFilterListId");
b.Property<DateTime>("CreatedDateUtc")
.ValueGeneratedOnAdd()
.HasColumnType("TIMESTAMP");
b.HasKey("ForkFilterListId", "UpstreamFilterListId");
b.HasIndex("UpstreamFilterListId");
b.HasIndex("ForkFilterListId", "UpstreamFilterListId")
.IsUnique();
b.ToTable("forks");
});
modelBuilder.Entity("FilterLists.Data.Entities.Junctions.Merge", b =>
{
b.Property<int>("MergeFilterListId");
b.Property<int>("UpstreamFilterListId");
b.Property<DateTime>("CreatedDateUtc")
.ValueGeneratedOnAdd()
.HasColumnType("TIMESTAMP");
b.HasKey("MergeFilterListId", "UpstreamFilterListId");
b.HasIndex("UpstreamFilterListId");
b.HasIndex("MergeFilterListId", "UpstreamFilterListId")
.IsUnique();
b.ToTable("merges");
});
modelBuilder.Entity("FilterLists.Data.Entities.Junctions.SnapshotRule", b =>
{
b.Property<int>("SnapshotId");
b.Property<int>("RuleId");
b.Property<DateTime>("CreatedDateUtc")
.ValueGeneratedOnAdd()
.HasColumnType("TIMESTAMP");
b.HasKey("SnapshotId", "RuleId");
b.HasIndex("RuleId");
b.HasIndex("SnapshotId", "RuleId")
.IsUnique();
b.ToTable("snapshots_rules");
});
modelBuilder.Entity("FilterLists.Data.Entities.Junctions.SoftwareSyntax", b =>
{
b.Property<int>("SoftwareId");
b.Property<int>("SyntaxId");
b.Property<DateTime>("CreatedDateUtc")
.ValueGeneratedOnAdd()
.HasColumnType("TIMESTAMP");
b.HasKey("SoftwareId", "SyntaxId");
b.HasIndex("SyntaxId");
b.HasIndex("SoftwareId", "SyntaxId")
.IsUnique();
b.ToTable("software_syntaxes");
});
modelBuilder.Entity("FilterLists.Data.Entities.Language", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("SMALLINT UNSIGNED");
b.Property<DateTime>("CreatedDateUtc")
.ValueGeneratedOnAdd()
.HasColumnType("TIMESTAMP");
b.Property<string>("Iso6391")
.ValueGeneratedOnAdd()
.HasColumnType("VARCHAR(2)")
.HasDefaultValueSql("NULL");
b.Property<string>("Iso6392")
.ValueGeneratedOnAdd()
.HasColumnType("VARCHAR(3)")
.HasDefaultValueSql("NULL");
b.Property<string>("Iso6392B")
.ValueGeneratedOnAdd()
.HasColumnType("VARCHAR(3)")
.HasDefaultValueSql("NULL");
b.Property<string>("Iso6392T")
.ValueGeneratedOnAdd()
.HasColumnType("VARCHAR(3)")
.HasDefaultValueSql("NULL");
b.Property<string>("Iso6393")
.ValueGeneratedOnAdd()
.HasColumnType("VARCHAR(3)")
.HasDefaultValueSql("NULL");
b.Property<string>("LocalName")
.ValueGeneratedOnAdd()
.HasColumnType("VARCHAR(126)")
.HasDefaultValueSql("NULL");
b.Property<DateTime>("ModifiedDateUtc")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("TIMESTAMP");
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasColumnType("VARCHAR(126)")
.HasDefaultValueSql("NULL");
b.HasKey("Id");
b.ToTable("languages");
});
modelBuilder.Entity("FilterLists.Data.Entities.License", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("SMALLINT UNSIGNED");
b.Property<DateTime>("CreatedDateUtc")
.ValueGeneratedOnAdd()
.HasColumnType("TIMESTAMP");
b.Property<string>("DescriptionUrl")
.HasColumnType("TEXT");
b.Property<DateTime>("ModifiedDateUtc")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("TIMESTAMP");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("VARCHAR(126)");
b.Property<bool>("PermissiveAdaptation");
b.Property<bool>("PermissiveCommercial");
b.HasKey("Id");
b.ToTable("licenses");
});
modelBuilder.Entity("FilterLists.Data.Entities.Maintainer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("SMALLINT UNSIGNED");
b.Property<DateTime>("CreatedDateUtc")
.ValueGeneratedOnAdd()
.HasColumnType("TIMESTAMP");
b.Property<string>("EmailAddress")
.ValueGeneratedOnAdd()
.HasColumnType("VARCHAR(126)")
.HasDefaultValueSql("NULL");
b.Property<string>("HomeUrl")
.HasColumnType("TEXT");
b.Property<DateTime>("ModifiedDateUtc")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("TIMESTAMP");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("VARCHAR(126)");
b.Property<string>("TwitterHandle")
.ValueGeneratedOnAdd()
.HasColumnType("VARCHAR(126)")
.HasDefaultValueSql("NULL");
b.HasKey("Id");
b.ToTable("maintainers");
});
modelBuilder.Entity("FilterLists.Data.Entities.Rule", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("BIGINT UNSIGNED");
b.Property<DateTime>("CreatedDateUtc")
.ValueGeneratedOnAdd()
.HasColumnType("TIMESTAMP");
b.Property<string>("Raw")
.IsRequired()
.HasColumnType("VARCHAR(8192)");
b.HasKey("Id");
b.ToTable("rules");
});
modelBuilder.Entity("FilterLists.Data.Entities.Snapshot", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("MEDIUMINT UNSIGNED");
b.Property<DateTime>("CreatedDateUtc")
.ValueGeneratedOnAdd()
.HasColumnType("TIMESTAMP");
b.Property<int>("FilterListId");
b.Property<int?>("HttpStatusCode")
.HasColumnType("SMALLINT UNSIGNED");
b.HasKey("Id");
b.HasIndex("FilterListId");
b.ToTable("snapshots");
});
modelBuilder.Entity("FilterLists.Data.Entities.Software", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("SMALLINT UNSIGNED");
b.Property<DateTime>("CreatedDateUtc")
.ValueGeneratedOnAdd()
.HasColumnType("TIMESTAMP");
b.Property<string>("DownloadUrl")
.HasColumnType("TEXT");
b.Property<string>("HomeUrl")
.HasColumnType("TEXT");
b.Property<DateTime>("ModifiedDateUtc")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("TIMESTAMP");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("VARCHAR(126)");
b.HasKey("Id");
b.ToTable("software");
});
modelBuilder.Entity("FilterLists.Data.Entities.Syntax", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("SMALLINT UNSIGNED");
b.Property<DateTime>("CreatedDateUtc")
.ValueGeneratedOnAdd()
.HasColumnType("TIMESTAMP");
b.Property<string>("DefinitionUrl")
.HasColumnType("TEXT");
b.Property<DateTime>("ModifiedDateUtc")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("TIMESTAMP");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("VARCHAR(126)");
b.HasKey("Id");
b.ToTable("syntaxes");
});
modelBuilder.Entity("FilterLists.Data.Entities.FilterList", b =>
{
b.HasOne("FilterLists.Data.Entities.License", "License")
.WithMany("FilterLists")
.HasForeignKey("LicenseId");
b.HasOne("FilterLists.Data.Entities.Syntax", "Syntax")
.WithMany("FilterLists")
.HasForeignKey("SyntaxId");
});
modelBuilder.Entity("FilterLists.Data.Entities.Junctions.FilterListLanguage", b =>
{
b.HasOne("FilterLists.Data.Entities.FilterList", "FilterList")
.WithMany("FilterListLanguages")
.HasForeignKey("FilterListId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("FilterLists.Data.Entities.Language", "Language")
.WithMany("FilterListLanguages")
.HasForeignKey("LanguageId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("FilterLists.Data.Entities.Junctions.FilterListMaintainer", b =>
{
b.HasOne("FilterLists.Data.Entities.FilterList", "FilterList")
.WithMany("FilterListMaintainers")
.HasForeignKey("FilterListId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("FilterLists.Data.Entities.Maintainer", "Maintainer")
.WithMany("FilterListMaintainers")
.HasForeignKey("MaintainerId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("FilterLists.Data.Entities.Junctions.Fork", b =>
{
b.HasOne("FilterLists.Data.Entities.FilterList", "ForkFilterList")
.WithMany("ForkFilterLists")
.HasForeignKey("ForkFilterListId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("FilterLists.Data.Entities.FilterList", "UpstreamFilterList")
.WithMany("UpstreamForkFilterLists")
.HasForeignKey("UpstreamFilterListId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("FilterLists.Data.Entities.Junctions.Merge", b =>
{
b.HasOne("FilterLists.Data.Entities.FilterList", "MergeFilterList")
.WithMany("MergeFilterLists")
.HasForeignKey("MergeFilterListId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("FilterLists.Data.Entities.FilterList", "UpstreamFilterList")
.WithMany("UpstreamMergeFilterLists")
.HasForeignKey("UpstreamFilterListId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("FilterLists.Data.Entities.Junctions.SnapshotRule", b =>
{
b.HasOne("FilterLists.Data.Entities.Rule", "Rule")
.WithMany("SnapshotRules")
.HasForeignKey("RuleId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("FilterLists.Data.Entities.Snapshot", "Snapshot")
.WithMany("SnapshotRules")
.HasForeignKey("SnapshotId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("FilterLists.Data.Entities.Junctions.SoftwareSyntax", b =>
{
b.HasOne("FilterLists.Data.Entities.Software", "Software")
.WithMany("SoftwareSyntaxes")
.HasForeignKey("SoftwareId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("FilterLists.Data.Entities.Syntax", "Syntax")
.WithMany("SoftwareSyntaxes")
.HasForeignKey("SyntaxId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("FilterLists.Data.Entities.Snapshot", b =>
{
b.HasOne("FilterLists.Data.Entities.FilterList", "FilterList")
.WithMany("Snapshots")
.HasForeignKey("FilterListId")
.OnDelete(DeleteBehavior.Cascade);
});
#pragma warning restore 612, 618
}
}
}

View file

@ -0,0 +1,75 @@
using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;
namespace FilterLists.Api.Migrations
{
public partial class AddJunctionCompositeIndices : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateIndex(
name: "IX_software_syntaxes_SoftwareId_SyntaxId",
table: "software_syntaxes",
columns: new[] { "SoftwareId", "SyntaxId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_snapshots_rules_SnapshotId_RuleId",
table: "snapshots_rules",
columns: new[] { "SnapshotId", "RuleId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_merges_MergeFilterListId_UpstreamFilterListId",
table: "merges",
columns: new[] { "MergeFilterListId", "UpstreamFilterListId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_forks_ForkFilterListId_UpstreamFilterListId",
table: "forks",
columns: new[] { "ForkFilterListId", "UpstreamFilterListId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_filterlists_maintainers_FilterListId_MaintainerId",
table: "filterlists_maintainers",
columns: new[] { "FilterListId", "MaintainerId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_filterlists_languages_FilterListId_LanguageId",
table: "filterlists_languages",
columns: new[] { "FilterListId", "LanguageId" },
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_software_syntaxes_SoftwareId_SyntaxId",
table: "software_syntaxes");
migrationBuilder.DropIndex(
name: "IX_snapshots_rules_SnapshotId_RuleId",
table: "snapshots_rules");
migrationBuilder.DropIndex(
name: "IX_merges_MergeFilterListId_UpstreamFilterListId",
table: "merges");
migrationBuilder.DropIndex(
name: "IX_forks_ForkFilterListId_UpstreamFilterListId",
table: "forks");
migrationBuilder.DropIndex(
name: "IX_filterlists_maintainers_FilterListId_MaintainerId",
table: "filterlists_maintainers");
migrationBuilder.DropIndex(
name: "IX_filterlists_languages_FilterListId_LanguageId",
table: "filterlists_languages");
}
}
}

View file

@ -98,6 +98,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasIndex("LanguageId");
b.HasIndex("FilterListId", "LanguageId")
.IsUnique();
b.ToTable("filterlists_languages");
});
@ -115,6 +118,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasIndex("MaintainerId");
b.HasIndex("FilterListId", "MaintainerId")
.IsUnique();
b.ToTable("filterlists_maintainers");
});
@ -132,6 +138,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasIndex("UpstreamFilterListId");
b.HasIndex("ForkFilterListId", "UpstreamFilterListId")
.IsUnique();
b.ToTable("forks");
});
@ -149,6 +158,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasIndex("UpstreamFilterListId");
b.HasIndex("MergeFilterListId", "UpstreamFilterListId")
.IsUnique();
b.ToTable("merges");
});
@ -166,6 +178,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasIndex("RuleId");
b.HasIndex("SnapshotId", "RuleId")
.IsUnique();
b.ToTable("snapshots_rules");
});
@ -183,6 +198,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasIndex("SyntaxId");
b.HasIndex("SoftwareId", "SyntaxId")
.IsUnique();
b.ToTable("software_syntaxes");
});

View file

@ -11,6 +11,13 @@ 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.FilterListId, x.LanguageId}).IsUnique();
entityTypeBuilder.HasOne(x => x.FilterList)
.WithMany(x => x.FilterListLanguages)
.HasForeignKey(x => x.FilterListId);
entityTypeBuilder.HasOne(x => x.Language)
.WithMany(x => x.FilterListLanguages)
.HasForeignKey(x => x.LanguageId);
}
}
}

View file

@ -11,6 +11,13 @@ 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.FilterListId, x.MaintainerId}).IsUnique();
entityTypeBuilder.HasOne(x => x.FilterList)
.WithMany(x => x.FilterListMaintainers)
.HasForeignKey(x => x.FilterListId);
entityTypeBuilder.HasOne(x => x.Maintainer)
.WithMany(x => x.FilterListMaintainers)
.HasForeignKey(x => x.MaintainerId);
}
}
}

View file

@ -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.ForkFilterListId, x.UpstreamFilterListId}).IsUnique();
entityTypeBuilder.HasOne(x => x.ForkFilterList)
.WithMany(x => x.ForkFilterLists)
.HasForeignKey(x => x.ForkFilterListId);

View file

@ -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.MergeFilterListId, x.UpstreamFilterListId}).IsUnique();
entityTypeBuilder.HasOne(x => x.MergeFilterList)
.WithMany(x => x.MergeFilterLists)
.HasForeignKey(x => x.MergeFilterListId);

View file

@ -11,6 +11,13 @@ 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.SnapshotId, x.RuleId}).IsUnique();
entityTypeBuilder.HasOne(x => x.Snapshot)
.WithMany(x => x.SnapshotRules)
.HasForeignKey(x => x.SnapshotId);
entityTypeBuilder.HasOne(x => x.Rule)
.WithMany(x => x.SnapshotRules)
.HasForeignKey(x => x.RuleId);
}
}
}

View file

@ -11,6 +11,13 @@ public override void Configure(EntityTypeBuilder<SoftwareSyntax> entityTypeBuild
base.Configure(entityTypeBuilder);
entityTypeBuilder.ToTable("software_syntaxes");
entityTypeBuilder.HasKey(x => new {x.SoftwareId, x.SyntaxId});
entityTypeBuilder.HasIndex(x => new {x.SoftwareId, x.SyntaxId}).IsUnique();
entityTypeBuilder.HasOne(x => x.Software)
.WithMany(x => x.SoftwareSyntaxes)
.HasForeignKey(x => x.SoftwareId);
entityTypeBuilder.HasOne(x => x.Syntax)
.WithMany(x => x.SoftwareSyntaxes)
.HasForeignKey(x => x.SyntaxId);
}
}
}