generated from Ed-Fi-Exchange-OSS/Template-for-GitHub
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpsake-build-helpers.ps1
49 lines (41 loc) · 2.24 KB
/
psake-build-helpers.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# SPDX-License-Identifier: Apache-2.0
# Licensed to the Ed-Fi Alliance under one or more agreements.
# The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
# See the LICENSE and NOTICES files in the project root for more information.
function Remove-Directory-Silently($path) {
if (test-path $path) {
write-host "Deleting $path"
Remove-Item $path -recurse -force -ErrorAction SilentlyContinue | out-null
}
}
function Exist-Container($name) {
if (docker container ls -f Name=$name -aq) {
return $true
}
return $false
}
function Recreate-Docker-Db($containerName, $dbPort, $dbPass) {
if(Exist-Container $containerName) {
Write-Host "Removing $containerName"
exec { docker rm "$containerName" -f }
}
Write-Host "Creating $containerName"
exec { docker run -e 'ACCEPT_EULA=Y' --name "$containerName" -e "SA_PASSWORD=$dbPass" -p "${dbPort}:1433" -d "mcr.microsoft.com/mssql/server:2019-latest" }
Write-Host "Pausing for DB to come online"
Start-Sleep -s 15
Write-Host "DB ready at $containerName"
}
function Restore-Docker-Db($containerName, $bakDir, $bakFilename, $dbPass, $bakDb, $destDb) {
exec { docker exec "$containerName" mkdir -p "/var/opt/mssql/backup"}
Write-Host "Copying $bakDir/$bakFilename to container $containerName"
exec { docker cp "$bakDir/$bakFilename" "${containerName}:/var/opt/mssql/backup/$bakFilename" }
$restoreQuery = "RESTORE DATABASE $destDb FROM DISK='/var/opt/mssql/backup/$bakFilename' WITH REPLACE, MOVE '$bakDb`_log' TO '/var/opt/mssql/data/$destDb`_log.ldf', MOVE '$bakDb' TO '/var/opt/mssql/data/$destDb.mdf'"
$restoreQuery | Out-File "$bakDir/restore.sql"
Write-Host "Copying restore script to container $containerName"
exec { docker cp "$bakDir/restore.sql" "${containerName}:/var/opt/mssql/backup/restore.sql" }
Write-Host "Executing restore on $containerName"
exec { docker exec "$containerName" /opt/mssql-tools/bin/sqlcmd -S localhost -U 'sa' -P "$dbPass" -i '/var/opt/mssql/backup/restore.sql' }
}
function Update-Database($roundhouseConnString, $environment) {
exec { rh -f="./src/API/DatabaseMigrations/scripts" -c="$roundhouseConnString" -dc --env $environment --noninteractive } -workingDirectory .
}