Pipelines/Steps/SQL/Deploy-CustomDatabases.ps1

$ErrorActionPreference = "Stop"

Write-Output "Add custom databases started..."

if (($null -eq $SAFConfiguration.sql.customDatabases) -or ($SAFConfiguration.sql.customDatabases.Count -lt 1)) {
    Write-Output "No custom databases found."
}
else {

    $sqlServer = $SAFConfiguration.sql.serverName
    $sqlUser = $SAFConfiguration.sql.adminUsername
    $sqlAdminPassword = $SAFConfiguration.sql.adminPassword
    $sqlSitecorePassword = $SAFConfiguration.sql.sitecorePassword

    foreach ($db in $SAFConfiguration.sql.customDatabases) {
        DeployDacpac -SqlServer $sqlServer -Username $sqlUser -Password $sqlAdminPassword -LocalDbUsername $db.localDbUsername -LocalDbPassword $sqlSitecorePassword -Dacpac $db.dacpac -TargetDatabaseName $db.dbName
        foreach($sitecoreInstance in $SAFConfiguration.sitecore){
            $sitecoreInstallDir = $sitecoreInstance.installDir
            AddConnectionString -SqlServer $sqlServer -Database $targetDatabaseName -Username $db.localDbUsername -Password $sqlSitecorePassword -WebsiteRootDir $sitecoreInstallDir -ConnStringName $db.connectionStringName
        }
    }
}

Write-Output "Add custom databases done."