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) {
        if (!($null -eq $db.skip)) {
            if ($db.skip -eq $true) {
                Write-Warning "Adding of '$($db.dbName)' database skipped."
                continue
            }
        }
        else {
            DeployDacpac -SqlServer $sqlServer -Username $sqlUser -Password $sqlAdminPassword -LocalDbUsername $db.localDbUsername -LocalDbPassword $sqlSitecorePassword -Dacpac $db.dacpac -TargetDatabaseName $db.dbName
            AddConnectionString -SqlServer $sqlServer -Database $targetDatabaseName -Username $db.localDbUsername -Password $sqlSitecorePassword -WebsiteRootDir $SAFConfiguration.sitecore.installDir -ConnStringName $db.connectionStringName
        }
    }
}

Write-Output "Add custom databases done."