Created
October 7, 2019 18:56
-
-
Save davidsk/c886daafa60dc374d2f19198c494a67f to your computer and use it in GitHub Desktop.
Synchronise EF Core Database with Code
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
param ( | |
[Parameter(Mandatory=$true)][string]$project | |
[Parameter(Mandatory=$true)][string]$context | |
[string]$startupProject | |
) | |
Set-Location $PSScriptRoot | |
if (-Not ($startupProject)) | |
{ | |
$startupProject = $project | |
} | |
# check current dotnet version | |
$dotnet_version = dotnet --version | |
# check whether global tools are supported | |
if([System.Version]$dotnet_version -ge [System.Version]"2.1.301") | |
{ | |
# get last migration | |
$lastMigration = dotnet ef migrations list --project $project --startup-project $startupProject --context $context | Select-Object -Last 1 | |
dotnet ef database update $lastMigration --project $project --startup-project $startupProject --context $context | |
} | |
else | |
{ | |
Write-Output "Your version of .NET Core is $dotnet_version, version 2.1.301 or greater is required" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment