-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathBuildtSQLtDacpac.ps1
More file actions
44 lines (33 loc) · 2.22 KB
/
Copy pathBuildtSQLtDacpac.ps1
File metadata and controls
44 lines (33 loc) · 2.22 KB
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
Param(
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string] $ServerName,
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string] $DatabaseName,
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string] $Login,
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string] $SqlCmdPath,
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string] $SqlPackagePath
);
<#
Technically this should be called by a matrixed job, so that dacpacs are built for all versions (we support, like not 2005, 2008)
#>
$scriptpath = $MyInvocation.MyCommand.Path;
$dir = Split-Path $scriptpath;
.($dir+"\CommonFunctionsAndMethods.ps1");
$OutputPath = $dir + "/output/DacpacBuild/";
$TempPath = $dir + "/temp/DacpacBuild/";
$ServerNameTrimmed = $ServerName.Trim();
$LoginTrimmed = $Login.Trim("'").Trim();
Log-Output "FileLocation: $dir";
Push-Location;
Set-Location $TempPath;
Exec-SqlFileOrQuery -ServerName $ServerNameTrimmed -Login "$LoginTrimmed" -SqlCmdPath $SqlCmdPath -FileNames @("ResetValidationServer.sql","PrepareServer.sql");
Exec-SqlFileOrQuery -ServerName $ServerNameTrimmed -Login "$LoginTrimmed" -SqlCmdPath $SqlCmdPath -FileNames ($dir+"/CreateBuildDb.sql") -Database "tempdb" -AdditionalParameters ('-v NewDbName="'+$DatabaseName+'"');
Exec-SqlFileOrQuery -ServerName $ServerNameTrimmed -Login "$LoginTrimmed" -SqlCmdPath $SqlCmdPath -FileNames "tSQLt.class.sql" -Database "$DatabaseName";
$FriendlySQLServerVersion = Get-FriendlySQLServerVersion -ServerName $ServerNameTrimmed -Login "$LoginTrimmed" -SqlCmdPath $SqlCmdPath;
$tSQLtDacpacFileName = "tSQLt."+$FriendlySQLServerVersion+".dacpac";
$tSQLtApplicationName = "tSQLt."+$FriendlySQLServerVersion;
$tSQLtConnectionString = Get-SqlConnectionString -ServerName $ServerNameTrimmed -Login "$LoginTrimmed" -DatabaseName $DatabaseName;
& "$SqlPackagePath\sqlpackage.exe" /a:Extract /scs:"$tSQLtConnectionString" /tf:"$tSQLtDacpacFileName" /p:DacApplicationName="$tSQLtApplicationName" /p:IgnoreExtendedProperties=true /p:DacMajorVersion=0 /p:DacMinorVersion=1 /p:ExtractUsageProperties=false
if($LASTEXITCODE -ne 0) {
throw "error during execution of dacpac " + $tSQLtDacpacFileName;
}
Copy-Item -Path $tSQLtDacpacFileName -Destination $OutputPath;
Pop-Location;