prepare db for de-duped SnapshotRule

This commit is contained in:
Collin M. Barrett 2018-02-10 07:14:07 -06:00
parent d1b180b45c
commit 42eac2ed94
14 changed files with 117 additions and 608 deletions

View file

@ -1,505 +0,0 @@
// <auto-generated />
using System;
using FilterLists.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
namespace FilterLists.Api.Migrations
{
[DbContext(typeof(FilterListsDbContext))]
[Migration("20180208153839_InitialCreate")]
partial class InitialCreate
{
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", "FilterListId");
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", "FilterListId");
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", "ForkFilterListId");
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", "MergeFilterListId");
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", "SnapshotId");
b.ToTable("snapshots_rules");
});
modelBuilder.Entity("FilterLists.Data.Entities.Junctions.SoftwareSyntax", b =>
{
b.Property<int>("SyntaxId");
b.Property<int>("SoftwareId");
b.Property<DateTime>("CreatedDateUtc")
.ValueGeneratedOnAdd()
.HasColumnType("TIMESTAMP");
b.HasKey("SyntaxId", "SoftwareId");
b.HasIndex("SoftwareId", "SyntaxId");
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("TINYINT 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("INT 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("TINYINT 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("TINYINT 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

@ -1,33 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace FilterLists.Api.Migrations
{
public partial class ConvertHttpStatusCodeToVarchar : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
"HttpStatusCode",
"snapshots",
"VARCHAR(3)",
nullable: true,
defaultValueSql: "NULL",
oldClrType: typeof(int),
oldType: "SMALLINT UNSIGNED",
oldNullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
"HttpStatusCode",
"snapshots",
"SMALLINT UNSIGNED",
nullable: true,
oldClrType: typeof(string),
oldType: "VARCHAR(3)",
oldNullable: true,
oldDefaultValueSql: "NULL");
}
}
}

View file

@ -10,8 +10,8 @@
namespace FilterLists.Api.Migrations
{
[DbContext(typeof(FilterListsDbContext))]
[Migration("20180209190024_ConvertHttpStatusCodeToVarchar")]
partial class ConvertHttpStatusCodeToVarchar
[Migration("20180210130730_InitialCreate")]
partial class InitialCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
@ -97,7 +97,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
b.HasKey("FilterListId", "LanguageId");
b.HasIndex("LanguageId", "FilterListId");
b.HasIndex("LanguageId");
b.ToTable("filterlists_languages");
});
@ -114,7 +114,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
b.HasKey("FilterListId", "MaintainerId");
b.HasIndex("MaintainerId", "FilterListId");
b.HasIndex("MaintainerId");
b.ToTable("filterlists_maintainers");
});
@ -131,7 +131,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
b.HasKey("ForkFilterListId", "UpstreamFilterListId");
b.HasIndex("UpstreamFilterListId", "ForkFilterListId");
b.HasIndex("UpstreamFilterListId");
b.ToTable("forks");
});
@ -148,14 +148,14 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
b.HasKey("MergeFilterListId", "UpstreamFilterListId");
b.HasIndex("UpstreamFilterListId", "MergeFilterListId");
b.HasIndex("UpstreamFilterListId");
b.ToTable("merges");
});
modelBuilder.Entity("FilterLists.Data.Entities.Junctions.SnapshotRule", b =>
{
b.Property<int>("SnapshotId");
b.Property<int>("AddedBySnapshotId");
b.Property<int>("RuleId");
@ -163,9 +163,17 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
.ValueGeneratedOnAdd()
.HasColumnType("TIMESTAMP");
b.HasKey("SnapshotId", "RuleId");
b.Property<DateTime>("ModifiedDateUtc")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("TIMESTAMP");
b.HasIndex("RuleId", "SnapshotId");
b.Property<int?>("RemovedBySnapshotId");
b.HasKey("AddedBySnapshotId", "RuleId");
b.HasIndex("RemovedBySnapshotId");
b.HasIndex("RuleId");
b.ToTable("snapshots_rules");
});
@ -182,7 +190,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
b.HasKey("SyntaxId", "SoftwareId");
b.HasIndex("SoftwareId", "SyntaxId");
b.HasIndex("SoftwareId");
b.ToTable("software_syntaxes");
});
@ -470,15 +478,20 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
modelBuilder.Entity("FilterLists.Data.Entities.Junctions.SnapshotRule", b =>
{
b.HasOne("FilterLists.Data.Entities.Snapshot", "AddedBySnapshot")
.WithMany("AddedSnapshotRules")
.HasForeignKey("AddedBySnapshotId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("FilterLists.Data.Entities.Snapshot", "RemovedBySnapshot")
.WithMany("RemovedSnapshotRules")
.HasForeignKey("RemovedBySnapshotId")
.OnDelete(DeleteBehavior.Cascade);
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 =>

View file

@ -301,7 +301,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn),
FilterListId = table.Column<int>(nullable: false),
HttpStatusCode = table.Column<int>("SMALLINT UNSIGNED", nullable: true)
HttpStatusCode = table.Column<string>("VARCHAR(3)", nullable: true, defaultValueSql: "NULL")
},
constraints: table =>
{
@ -318,27 +318,35 @@ protected override void Up(MigrationBuilder migrationBuilder)
"snapshots_rules",
table => new
{
SnapshotId = table.Column<int>(nullable: false),
AddedBySnapshotId = table.Column<int>(nullable: false),
RuleId = table.Column<int>(nullable: false),
CreatedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false)
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn)
MySqlValueGenerationStrategy.IdentityColumn),
ModifiedDateUtc = table.Column<DateTime>("TIMESTAMP", nullable: false),
RemovedBySnapshotId = table.Column<int>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_snapshots_rules", x => new {x.SnapshotId, x.RuleId});
table.PrimaryKey("PK_snapshots_rules", x => new {x.AddedBySnapshotId, x.RuleId});
table.ForeignKey(
"FK_snapshots_rules_snapshots_AddedBySnapshotId",
x => x.AddedBySnapshotId,
"snapshots",
"Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
"FK_snapshots_rules_snapshots_RemovedBySnapshotId",
x => x.RemovedBySnapshotId,
"snapshots",
"Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
"FK_snapshots_rules_rules_RuleId",
x => x.RuleId,
"rules",
"Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
"FK_snapshots_rules_snapshots_SnapshotId",
x => x.SnapshotId,
"snapshots",
"Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
@ -352,24 +360,24 @@ protected override void Up(MigrationBuilder migrationBuilder)
"SyntaxId");
migrationBuilder.CreateIndex(
"IX_filterlists_languages_LanguageId_FilterListId",
"IX_filterlists_languages_LanguageId",
"filterlists_languages",
new[] {"LanguageId", "FilterListId"});
"LanguageId");
migrationBuilder.CreateIndex(
"IX_filterlists_maintainers_MaintainerId_FilterListId",
"IX_filterlists_maintainers_MaintainerId",
"filterlists_maintainers",
new[] {"MaintainerId", "FilterListId"});
"MaintainerId");
migrationBuilder.CreateIndex(
"IX_forks_UpstreamFilterListId_ForkFilterListId",
"IX_forks_UpstreamFilterListId",
"forks",
new[] {"UpstreamFilterListId", "ForkFilterListId"});
"UpstreamFilterListId");
migrationBuilder.CreateIndex(
"IX_merges_UpstreamFilterListId_MergeFilterListId",
"IX_merges_UpstreamFilterListId",
"merges",
new[] {"UpstreamFilterListId", "MergeFilterListId"});
"UpstreamFilterListId");
migrationBuilder.CreateIndex(
"IX_snapshots_FilterListId",
@ -377,14 +385,19 @@ protected override void Up(MigrationBuilder migrationBuilder)
"FilterListId");
migrationBuilder.CreateIndex(
"IX_snapshots_rules_RuleId_SnapshotId",
"IX_snapshots_rules_RemovedBySnapshotId",
"snapshots_rules",
new[] {"RuleId", "SnapshotId"});
"RemovedBySnapshotId");
migrationBuilder.CreateIndex(
"IX_software_syntaxes_SoftwareId_SyntaxId",
"IX_snapshots_rules_RuleId",
"snapshots_rules",
"RuleId");
migrationBuilder.CreateIndex(
"IX_software_syntaxes_SoftwareId",
"software_syntaxes",
new[] {"SoftwareId", "SyntaxId"});
"SoftwareId");
}
protected override void Down(MigrationBuilder migrationBuilder)
@ -414,10 +427,10 @@ protected override void Down(MigrationBuilder migrationBuilder)
"maintainers");
migrationBuilder.DropTable(
"rules");
"snapshots");
migrationBuilder.DropTable(
"snapshots");
"rules");
migrationBuilder.DropTable(
"software");

View file

@ -95,7 +95,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasKey("FilterListId", "LanguageId");
b.HasIndex("LanguageId", "FilterListId");
b.HasIndex("LanguageId");
b.ToTable("filterlists_languages");
});
@ -112,7 +112,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasKey("FilterListId", "MaintainerId");
b.HasIndex("MaintainerId", "FilterListId");
b.HasIndex("MaintainerId");
b.ToTable("filterlists_maintainers");
});
@ -129,7 +129,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasKey("ForkFilterListId", "UpstreamFilterListId");
b.HasIndex("UpstreamFilterListId", "ForkFilterListId");
b.HasIndex("UpstreamFilterListId");
b.ToTable("forks");
});
@ -146,14 +146,14 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasKey("MergeFilterListId", "UpstreamFilterListId");
b.HasIndex("UpstreamFilterListId", "MergeFilterListId");
b.HasIndex("UpstreamFilterListId");
b.ToTable("merges");
});
modelBuilder.Entity("FilterLists.Data.Entities.Junctions.SnapshotRule", b =>
{
b.Property<int>("SnapshotId");
b.Property<int>("AddedBySnapshotId");
b.Property<int>("RuleId");
@ -161,9 +161,17 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.ValueGeneratedOnAdd()
.HasColumnType("TIMESTAMP");
b.HasKey("SnapshotId", "RuleId");
b.Property<DateTime>("ModifiedDateUtc")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("TIMESTAMP");
b.HasIndex("RuleId", "SnapshotId");
b.Property<int?>("RemovedBySnapshotId");
b.HasKey("AddedBySnapshotId", "RuleId");
b.HasIndex("RemovedBySnapshotId");
b.HasIndex("RuleId");
b.ToTable("snapshots_rules");
});
@ -180,7 +188,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasKey("SyntaxId", "SoftwareId");
b.HasIndex("SoftwareId", "SyntaxId");
b.HasIndex("SoftwareId");
b.ToTable("software_syntaxes");
});
@ -468,15 +476,20 @@ protected override void BuildModel(ModelBuilder modelBuilder)
modelBuilder.Entity("FilterLists.Data.Entities.Junctions.SnapshotRule", b =>
{
b.HasOne("FilterLists.Data.Entities.Snapshot", "AddedBySnapshot")
.WithMany("AddedSnapshotRules")
.HasForeignKey("AddedBySnapshotId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("FilterLists.Data.Entities.Snapshot", "RemovedBySnapshot")
.WithMany("RemovedSnapshotRules")
.HasForeignKey("RemovedBySnapshotId")
.OnDelete(DeleteBehavior.Cascade);
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 =>

View file

@ -1,9 +1,14 @@
namespace FilterLists.Data.Entities.Junctions
using System;
namespace FilterLists.Data.Entities.Junctions
{
public class SnapshotRule : BaseJunction
{
public int SnapshotId { get; set; }
public Snapshot Snapshot { get; set; }
public DateTime ModifiedDateUtc { get; set; }
public int AddedBySnapshotId { get; set; }
public Snapshot AddedBySnapshot { get; set; }
public int? RemovedBySnapshotId { get; set; }
public Snapshot RemovedBySnapshot { get; set; }
public int RuleId { get; set; }
public Rule Rule { get; set; }
}

View file

@ -8,6 +8,7 @@ public class Snapshot : BaseEntity
public int FilterListId { get; set; }
public FilterList FilterList { get; set; }
public string HttpStatusCode { get; set; }
public ICollection<SnapshotRule> SnapshotRules { get; set; }
public ICollection<SnapshotRule> AddedSnapshotRules { get; set; }
public ICollection<SnapshotRule> RemovedSnapshotRules { get; set; }
}
}

View file

@ -11,7 +11,6 @@ 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);

View file

@ -11,7 +11,6 @@ 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);

View file

@ -11,7 +11,6 @@ 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);

View file

@ -11,7 +11,6 @@ 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);

View file

@ -10,11 +10,17 @@ 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);
entityTypeBuilder.HasKey(x => new {x.AddedBySnapshotId, x.RuleId});
entityTypeBuilder.Property(x => x.ModifiedDateUtc)
.HasColumnType("TIMESTAMP")
.ValueGeneratedOnAddOrUpdate();
entityTypeBuilder.HasOne(x => x.AddedBySnapshot)
.WithMany(x => x.AddedSnapshotRules)
.HasForeignKey(x => x.AddedBySnapshotId);
entityTypeBuilder.HasOne(x => x.RemovedBySnapshot)
.WithMany(x => x.RemovedSnapshotRules)
.HasForeignKey(x => x.RemovedBySnapshotId)
.OnDelete(DeleteBehavior.Cascade);
entityTypeBuilder.HasOne(x => x.Rule)
.WithMany(x => x.SnapshotRules)
.HasForeignKey(x => x.RuleId);

View file

@ -11,7 +11,6 @@ public override void Configure(EntityTypeBuilder<SoftwareSyntax> entityTypeBuild
base.Configure(entityTypeBuilder);
entityTypeBuilder.ToTable("software_syntaxes");
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);

View file

@ -23,6 +23,7 @@ public SnapshotBatchDe(FilterListsDbContext dbContext, Snapshot snapshot, IEnume
this.rawRules = rawRules;
}
//TODO: support de-duplicated SnapshotRule
public async Task SaveSnapshotBatchAsync()
{
AddNewRules();
@ -41,11 +42,11 @@ private void AddNewRules()
private void AddSnapshotRules()
{
if (snapshot.SnapshotRules == null)
snapshot.SnapshotRules = new List<SnapshotRule>();
snapshot.SnapshotRules.AddRange(preExistingSnapshotRules
if (snapshot.AddedSnapshotRules == null)
snapshot.AddedSnapshotRules = new List<SnapshotRule>();
snapshot.AddedSnapshotRules.AddRange(preExistingSnapshotRules
.Concat(newSnapshotRules)
.Select(rule => new SnapshotRule {Rule = rule, Snapshot = snapshot})
.Select(rule => new SnapshotRule {Rule = rule, AddedBySnapshot = snapshot})
.ToList());
}
}