Add extra migration scripts.

This commit is contained in:
Jared Goodwin 2023-08-01 11:35:40 -07:00
parent 45845e8877
commit 64c21258ef
3 changed files with 99 additions and 0 deletions

View File

@ -13,6 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Utilities", "Utilities", "{
Utilities\Get-PSCommands.ps1 = Utilities\Get-PSCommands.ps1
Utilities\Get-WindowsCommands.ps1 = Utilities\Get-WindowsCommands.ps1
Utilities\Publish.ps1 = Utilities\Publish.ps1
Utilities\Remove-Migration.ps1 = Utilities\Remove-Migration.ps1
Utilities\signtool.exe = Utilities\signtool.exe
EndProjectSection
EndProject

View File

@ -0,0 +1,45 @@
$ErrorActionPreference = "Stop"
function Replace-LineInFile($FilePath, $MatchPattern, $ReplaceLineWith, $MaxCount = -1){
$FullPath = (Get-Item -Path $FilePath).FullName
[string[]]$Content = Get-Content -Path $FullPath
$Count = 0
for ($i = 0; $i -lt $Content.Length; $i++)
{
if ($Content[$i] -ne $null -and $Content[$i].Contains($MatchPattern)) {
$Content[$i] = $ReplaceLineWith
$Count++
}
if ($MaxCount -gt 0 -and $Count -ge $MaxCount) {
break
}
}
[System.IO.File]::WriteAllLines($FullPath, $Content)
}
if ($PSScriptRoot) {
$Root = (Get-Item -Path $PSScriptRoot).Parent.FullName + "\Server"
}
else {
$Root = (Get-Item -Path (Get-Location).Path).Parent.FullName + "\Server"
}
Push-Location "$Root"
Replace-LineInFile -FilePath "$Root\appsettings.json" -MatchPattern '"DBProvider":' -ReplaceLineWith ' "DBProvider": "SQLite",' -MaxCount 1
dotnet ef migrations remove --context "SqliteDbContext"
Replace-LineInFile -FilePath "$Root\appsettings.json" -MatchPattern '"DBProvider":' -ReplaceLineWith ' "DBProvider": "SQLServer",' -MaxCount 1
dotnet ef migrations remove --context "SqlServerDbContext"
Replace-LineInFile -FilePath "$Root\appsettings.json" -MatchPattern '"DBProvider":' -ReplaceLineWith ' "DBProvider": "PostgreSQL",' -MaxCount 1
dotnet ef migrations remove --context "PostgreSqlDbContext"
Replace-LineInFile -FilePath "$Root\appsettings.json" -MatchPattern '"DBProvider":' -ReplaceLineWith ' "DBProvider": "SQLite",' -MaxCount 1
Pop-Location

View File

@ -0,0 +1,53 @@
param(
[string]$MigrationName
)
if (!$MigrationName) {
exit 1
}
$ErrorActionPreference = "Stop"
function Replace-LineInFile($FilePath, $MatchPattern, $ReplaceLineWith, $MaxCount = -1){
$FullPath = (Get-Item -Path $FilePath).FullName
[string[]]$Content = Get-Content -Path $FullPath
$Count = 0
for ($i = 0; $i -lt $Content.Length; $i++)
{
if ($Content[$i] -ne $null -and $Content[$i].Contains($MatchPattern)) {
$Content[$i] = $ReplaceLineWith
$Count++
}
if ($MaxCount -gt 0 -and $Count -ge $MaxCount) {
break
}
}
[System.IO.File]::WriteAllLines($FullPath, $Content)
}
if ($PSScriptRoot) {
$Root = (Get-Item -Path $PSScriptRoot).Parent.FullName + "\Server"
}
else {
$Root = (Get-Item -Path (Get-Location).Path).Parent.FullName + "\Server"
}
Push-Location "$Root"
Replace-LineInFile -FilePath "$Root\appsettings.json" -MatchPattern '"DBProvider":' -ReplaceLineWith ' "DBProvider": "SQLite",' -MaxCount 1
dotnet ef database update $MigrationName --context "SqliteDbContext"
Replace-LineInFile -FilePath "$Root\appsettings.json" -MatchPattern '"DBProvider":' -ReplaceLineWith ' "DBProvider": "SQLServer",' -MaxCount 1
dotnet ef database update $MigrationName --context "SqlServerDbContext"
Replace-LineInFile -FilePath "$Root\appsettings.json" -MatchPattern '"DBProvider":' -ReplaceLineWith ' "DBProvider": "PostgreSQL",' -MaxCount 1
dotnet ef database update $MigrationName --context "PostgreSqlDbContext"
Replace-LineInFile -FilePath "$Root\appsettings.json" -MatchPattern '"DBProvider":' -ReplaceLineWith ' "DBProvider": "SQLite",' -MaxCount 1
Pop-Location