-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from simon-reynolds/fix-altercolumn-ops
AlterColumn operations no longer create unnecessary migrations
- Loading branch information
Showing
6 changed files
with
88 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/EFCore.FSharp/Migrations/Internal/FSharpMigrationsModelDiffer.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
namespace EntityFrameworkCore.FSharp.Migrations.Internal | ||
|
||
open System.Runtime.InteropServices | ||
open Microsoft.EntityFrameworkCore.Metadata | ||
open Microsoft.EntityFrameworkCore.Migrations.Internal | ||
open Microsoft.EntityFrameworkCore.Migrations.Operations | ||
open EntityFrameworkCore.FSharp.SharedTypeExtensions | ||
open Microsoft.EntityFrameworkCore.Metadata.Internal | ||
|
||
type FSharpMigrationsModelDiffer | ||
( | ||
typeMappingSource, | ||
migrationsAnnotations, | ||
changeDetector, | ||
updateAdapterFactory, | ||
commandBatchPreparerDependencies | ||
) = | ||
inherit MigrationsModelDiffer | ||
( | ||
typeMappingSource, | ||
migrationsAnnotations, | ||
changeDetector, | ||
updateAdapterFactory, | ||
commandBatchPreparerDependencies | ||
) | ||
|
||
let isNullableType (p: IProperty) = | ||
let clrType = p.ClrType | ||
let isPrimaryKey = p.IsPrimaryKey() | ||
|
||
let isNullable = | ||
(isOptionType clrType || isNullableType clrType) | ||
|
||
isNullable && not isPrimaryKey | ||
|
||
override _.Diff | ||
( | ||
source: IColumn, | ||
target: IColumn, | ||
diffContext: MigrationsModelDiffer.DiffContext | ||
) : MigrationOperation seq = | ||
|
||
System.Console.WriteLine("Diffing columns") | ||
|
||
let sourceTypeProperty = | ||
(source.PropertyMappings |> Seq.head).Property | ||
|
||
let targetTypeProperty = | ||
(target.PropertyMappings |> Seq.head).Property | ||
|
||
(source :?> Column).IsNullable <- isNullableType sourceTypeProperty | ||
(target :?> Column).IsNullable <- isNullableType targetTypeProperty | ||
|
||
base.Diff(source, target, diffContext) | ||
|
||
override _.Add | ||
( | ||
source: IColumn, | ||
diffContext: MigrationsModelDiffer.DiffContext, | ||
[<Optional; DefaultParameterValue(false)>] ``inline``: bool | ||
) : MigrationOperation seq = | ||
|
||
let sourceTypeProperty = | ||
(source.PropertyMappings |> Seq.head).Property | ||
|
||
(source :?> Column).IsNullable <- isNullableType sourceTypeProperty | ||
|
||
base.Add(source, diffContext, ``inline``) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters