support list seeding, redo initial migration

This commit is contained in:
Collin M. Barrett 2017-10-28 15:02:58 -05:00
parent 23ae1d6d85
commit 6c55470644
8 changed files with 2569 additions and 13 deletions

View file

@ -11,7 +11,7 @@
"IssuesUrl": "https://github.com/johnsmith/mysamplelist/issues",
"FilterListLanguages": null,
"FilterListSoftware": null,
"MaintainerId": 0,
"MaintainerId": null,
"Name": "My Sample Advertisement Filter List",
"ViewUrl": "https://mysample.list/list.txt",
"Id": 0,
@ -28,7 +28,7 @@
"IssuesUrl": "https://github.com/johnsmith/mysamplelist/issues",
"FilterListLanguages": null,
"FilterListSoftware": null,
"MaintainerId": 0,
"MaintainerId": null,
"Name": "My Sample Malware Filter List",
"ViewUrl": "https://mysample.list/list.txt",
"Id": 0,

View file

@ -67,7 +67,10 @@
}
},
"MaintainerId": {
"type": "integer"
"type": [
"integer",
"null"
]
},
"Name": {
"type": [

2545
data/ListsSeed.json Normal file

File diff suppressed because it is too large Load diff

View file

@ -11,7 +11,7 @@
namespace FilterLists.Api.Migrations
{
[DbContext(typeof(FilterListsDbContext))]
[Migration("20171028013855_InitialCreate")]
[Migration("20171028200037_InitialCreate")]
partial class InitialCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -51,7 +51,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
b.Property<string>("IssuesUrl")
.HasMaxLength(2083);
b.Property<int>("MaintainerId");
b.Property<int?>("MaintainerId");
b.Property<DateTime>("ModifiedDateUtc")
.ValueGeneratedOnAddOrUpdate()
@ -214,8 +214,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
b.HasOne("FilterLists.Data.Entities.Maintainer")
.WithMany("FilterLists")
.HasForeignKey("MaintainerId")
.OnDelete(DeleteBehavior.Cascade);
.HasForeignKey("MaintainerId");
});
modelBuilder.Entity("FilterLists.Data.Entities.FilterListLanguage", b =>

View file

@ -83,7 +83,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
ForumUrl = table.Column<string>(type: "varchar(2083)", maxLength: 2083, nullable: true),
HomeUrl = table.Column<string>(type: "varchar(2083)", maxLength: 2083, nullable: true),
IssuesUrl = table.Column<string>(type: "varchar(2083)", maxLength: 2083, nullable: true),
MaintainerId = table.Column<int>(type: "int", nullable: false),
MaintainerId = table.Column<int>(type: "int", nullable: true),
ModifiedDateUtc = table.Column<DateTime>(type: "TIMESTAMP", nullable: false),
Name = table.Column<string>(type: "varchar(126)", maxLength: 126, nullable: false),
ViewUrl = table.Column<string>(type: "varchar(2083)", maxLength: 2083, nullable: true)
@ -96,7 +96,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
column: x => x.MaintainerId,
principalTable: "maintainers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(

View file

@ -50,7 +50,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<string>("IssuesUrl")
.HasMaxLength(2083);
b.Property<int>("MaintainerId");
b.Property<int?>("MaintainerId");
b.Property<DateTime>("ModifiedDateUtc")
.ValueGeneratedOnAddOrUpdate()
@ -213,8 +213,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
{
b.HasOne("FilterLists.Data.Entities.Maintainer")
.WithMany("FilterLists")
.HasForeignKey("MaintainerId")
.OnDelete(DeleteBehavior.Cascade);
.HasForeignKey("MaintainerId");
});
modelBuilder.Entity("FilterLists.Data.Entities.FilterListLanguage", b =>

View file

@ -16,6 +16,7 @@ public static void Initialize(FilterListsDbContext filterListsDbContext)
{
filterListsDbContext.Database.Migrate();
InitializeLanguages(filterListsDbContext);
InitializeFilterLists(filterListsDbContext);
}
private static void InitializeLanguages(FilterListsDbContext filterListsDbContext)
@ -26,5 +27,14 @@ private static void InitializeLanguages(FilterListsDbContext filterListsDbContex
@"..\..\..\..\..\data\Languages.json")))));
filterListsDbContext.SaveChanges();
}
private static void InitializeFilterLists(FilterListsDbContext filterListsDbContext)
{
if (filterListsDbContext.FilterLists.Any()) return;
filterListsDbContext.AddRange(JsonConvert.DeserializeObject<List<FilterList>>(
File.ReadAllText(Path.GetFullPath(Path.Combine(AppContext.BaseDirectory + @"\",
@"..\..\..\..\..\data\ListsSeed.json")))));
filterListsDbContext.SaveChanges();
}
}
}

View file

@ -13,7 +13,7 @@ public class FilterList : BaseEntity
public string IssuesUrl { get; set; }
public ICollection<FilterListLanguage> FilterListLanguages { get; set; }
public ICollection<FilterListSoftware> FilterListSoftware { get; set; }
public int MaintainerId { get; set; }
public int? MaintainerId { get; set; }
public string Name { get; set; }
public string ViewUrl { get; set; }
}