Skip to content

Instantly share code, notes, and snippets.

@davidsk
Created October 7, 2019 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidsk/c886daafa60dc374d2f19198c494a67f to your computer and use it in GitHub Desktop.
Save davidsk/c886daafa60dc374d2f19198c494a67f to your computer and use it in GitHub Desktop.
Synchronise EF Core Database with Code
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