Skip to content

Commit

Permalink
Add extra migration scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Aug 1, 2023
1 parent 45845e8 commit 64c2125
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions Remotely.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions Utilities/Remove-Migration.ps1
Original file line number Diff line number Diff line change
@@ -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
53 changes: 53 additions & 0 deletions Utilities/Update-Database.ps1
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 64c2125

Please sign in to comment.