CoreWiki icon indicating copy to clipboard operation
CoreWiki copied to clipboard

Default homepage. Migration or first start wizard?

Open ashleybroughton opened this issue 6 years ago • 1 comments

TL;DR We get migration problems because Article Guids and Published date are seen as changed each time EntityFramework checks them against our model. https://github.com/csharpfritz/CoreWiki/blob/dev/CoreWiki/Models/ApplicationDbContext.cs#L25-L26


The way we are generating the home page article confuses entity framework into thinking that there are schema changes to be made because the AuthorId is checked against NewGuid(), and the Published Date is checked against the current date.

This means that any time we run the Add-Migration command or rebuild the database from scratch (either new developers cloning the repo, or to try and fix a problem), we will get a new migration with changes to just the AuthorId and Published fields.

Example (trimmed for brevity)

Add-Migration SomethingChanged1 --context ApplicationDbContext
Add-Migration SomethingChanged2 --context ApplicationDbContext
Add-Migration SomethingChanged3 --context ApplicationDbContext
// SomethingChanged1
protected override void Up(MigrationBuilder migrationBuilder)
{
    migrationBuilder.UpdateData(
        table: "Articles",
        keyColumn: "Id",
        keyValue: 1,
        columns: new[] { "AuthorId", "Published" },
        values: new object[] { new Guid("1df4fb2b-b87d-4f4d-aec5-3d504306ef31"), new DateTime(2018, 7, 10, 3, 51, 38, 753, DateTimeKind.Utc) });
}

// SomethingChanged2
protected override void Up(MigrationBuilder migrationBuilder)
{
    migrationBuilder.UpdateData(
        table: "Articles",
        keyColumn: "Id",
        keyValue: 1,
        columns: new[] { "AuthorId", "Published" },
        values: new object[] { new Guid("706f6d25-88b9-42f6-b7cc-94c4aaa0005a"), new DateTime(2018, 7, 10, 4, 3, 41, 35, DateTimeKind.Utc) });
}

// SomethingChanged3
protected override void Up(MigrationBuilder migrationBuilder)
{
    migrationBuilder.UpdateData(
        table: "Articles",
        keyColumn: "Id",
        keyValue: 1,
        columns: new[] { "AuthorId", "Published" },
        values: new object[] { new Guid("0e6e3e3b-9e1c-4e26-8e2b-0676205e25ad"), new DateTime(2018, 7, 10, 4, 5, 44, 44, DateTimeKind.Utc) });
}

// SomethingChanged{1,2,3}
protected override void Down(MigrationBuilder migrationBuilder)
{
    migrationBuilder.UpdateData(
        table: "Articles",
        keyColumn: "Id",
        keyValue: 1,
        columns: new[] { "AuthorId", "Published" },
        values: new object[] { new Guid("d1cebc50-390b-45b5-ab5e-d8bb589d46e5"), new DateTime(2018, 6, 19, 14, 31, 2, 265, DateTimeKind.Utc) });
}

We can either correct this issue by changing the way we seed data (using a static date and guid), or put the creation of the default home page into the start up wizard.

ashleybroughton avatar Jul 10 '18 04:07 ashleybroughton

Empty migration (as expected) after fixing.

image

ashleybroughton avatar Jul 10 '18 10:07 ashleybroughton