mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
Add extra migration scripts.
This commit is contained in:
parent
45845e8877
commit
64c21258ef
@ -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
|
||||
|
||||
45
Utilities/Remove-Migration.ps1
Normal file
45
Utilities/Remove-Migration.ps1
Normal 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
|
||||
53
Utilities/Update-Database.ps1
Normal file
53
Utilities/Update-Database.ps1
Normal 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
|
||||
Loading…
Reference in New Issue
Block a user