efcore / EFCore.FSharp

Adds F# design-time support to EF Core
MIT License
234 stars 26 forks source link

Primary Key constraint is missing from all new migrations #71

Closed GunnerGuyven closed 3 years ago

GunnerGuyven commented 3 years ago

Describe the bug The constraints argument is missing in most if not all instances of generated migrationBuilder.CreateTable calls. Especially table.PrimaryKey types.

I believe #68 may be related to this. That deals with conventional detection of PK, but it seems to be all PK constraints are actually missing in the 5.0.3-alpha2 release, even those that are manually demarked with the [<Key>] annotation.

To Reproduce Steps to reproduce the behavior:

  1. Create new table which includes a Primary Key annotated with [<Key>] in type definition
  2. Create new migration
  3. Observe the lack of a constraints argument in CreateTable call
  4. Perform database migration
  5. If successful, observe that no Primary Key is defined for database, and if Key was int type observe failure due to the inclusion of AUTO INCREMENT that is illegal in many databases engines outside of PK.

Expected behavior Inclusion of a clause similar to that seen in older 3.1.12 release

//EntityFrameworkCore.FSharp version 3.1.12
override this.Up(migrationBuilder:MigrationBuilder) =
        migrationBuilder.CreateTable(
            name = "OrderNumbers"
            ,columns = (fun table -> 
            {
                ID = table.Column<int>(nullable = false)
                    .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn)
                OrderNumber = table.Column<string>(nullable = true, maxLength = Nullable(10))
                TSO = table.Column<bool>(nullable = false)
                Treated = table.Column<bool>(nullable = false)
                Items = table.Column<int>(nullable = false)
                PiecesReceived = table.Column<int>(nullable = false)
                PiecesTreated = table.Column<int>(nullable = false)
                PiecesUnReleased = table.Column<int>(nullable = false)
                Memo = table.Column<string>(nullable = true)
            })
            ,constraints =
                (fun table -> 
                    table.PrimaryKey("PK_OrderNumbers", (fun x -> (x.ID) :> obj)) |> ignore
                ) 
            ) |> ignore
simon-reynolds commented 3 years ago

Hi @GunnerGuyven Resolved in https://www.nuget.org/packages/EntityFrameworkCore.FSharp/5.0.3-alpha5 if you can confirm?

GunnerGuyven commented 3 years ago

I can confirm. This appears to be addressed. I have a few edge cases yet to test, but seems good 👍

GunnerGuyven commented 3 years ago

All cases I have encountered are covered by this fix. Thank you!