internal/functions/Get-DbUpBuilder.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
50
51
52
53
54
55
function Get-DbUpBuilder {
    # Returns a DbUp builder with a proper connection object
    Param (
        [Parameter(Mandatory)]
        [object]$Connection,
        [string]$Schema,
        [DBOps.ConnectionType]$Type
    )
    $dbUp = [DbUp.DeployChanges]::To
    if ($Type -eq [DBOps.ConnectionType]::SqlServer) {
        if ($Schema) {
            $dbUp = [SqlServerExtensions]::SqlDatabase($dbUp, $dbUpConnection, $Schema)
        }
        else {
            $dbUp = [SqlServerExtensions]::SqlDatabase($dbUp, $dbUpConnection)
        }
    }
    elseif ($Type -eq [DBOps.ConnectionType]::Oracle) {
        if ($Schema) {
            $dbUp = [DbUp.Oracle.OracleExtensions]::OracleDatabase($dbUp, $dbUpConnection, $Schema)
        }
        else {
            $dbUp = [DbUp.Oracle.OracleExtensions]::OracleDatabase($dbUp, $dbUpConnection)
        }
    }
    elseif ($Type -eq [DBOps.ConnectionType]::MySQL) {
        if ($Schema) {
            $dbUp = [MySqlExtensions]::MySqlDatabase($dbUp, $dbUpConnection, $Schema)
        }
        else {
            $dbUp = [MySqlExtensions]::MySqlDatabase($dbUp, $dbUpConnection)
        }
    }
    elseif ($Type -eq [DBOps.ConnectionType]::MySQL) {
        if ($Schema) {
            $dbUp = [MySqlExtensions]::MySqlDatabase($dbUp, $dbUpConnection, $Schema)
        }
        else {
            $dbUp = [MySqlExtensions]::MySqlDatabase($dbUp, $dbUpConnection)
        }
    }
    elseif ($Type -eq [DBOps.ConnectionType]::PostgreSQL) {
        if ($Schema) {
            $dbUp = [PostgresqlExtensions]::PostgresqlDatabase($dbUp, $dbUpConnection, $Schema)
        }
        else {
            $dbUp = [PostgresqlExtensions]::PostgresqlDatabase($dbUp, $dbUpConnection)
        }
    }
    else {
        Stop-PSFFunction -Message "Unknown type $Type" -EnableException $true
        return
    }
    return $dbUp
}