-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdemo3.ps1
84 lines (51 loc) · 2.02 KB
/
demo3.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
###
# Deploy Script & Deploy Report
###
Clear-Host
$sqlpackage = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\150\sqlpackage.exe"
Set-Location "C:\GIT\NowinskiK\ssdt-training\src\sqlpackage\WideWorldImporters"
$dbName = "WideWorldImporters"
$dbpath = (Get-Location)
$dacpac = Join-Path -Path $dbpath -ChildPath "bin\Debug\$dbName.dacpac"
Write-Host "DacPac file path: $dacpac"
& $sqlpackage
#
# Another 2 popular options:
#
& $sqlpackage /Action:DeployReport
& $sqlpackage /Action:Script
#
# Generate REPORT
#
# New database (new4)
Clear-Host
$nowf = Get-Date -Format "yyyyMMddTHHmmss"
$outputFolder = Split-Path (Get-Location) -Parent | Join-Path -ChildPath "output"
New-Item -Path $outputFolder -ItemType Directory -ErrorAction:Ignore
$targetDb = "WideWorldImportersNew4"
$outputReportFile = "report-$nowf-$targetDb.xml"
$outputReportPath = Join-Path $outputFolder $outputReportFile
$publishProfile = Join-Path -Path $dbpath -ChildPath "WideWorldImportersNew.publish.xml"
& $sqlpackage /Action:DeployReport `
/SourceFile:$dacpac /Profile:$publishProfile /TargetDatabaseName:$targetDb `
/OutputPath:$outputReportPath
# Existing database (new3)
# Add new index on target database first
Clear-Host
$nowf = Get-Date -Format "yyyyMMddTHHmmss"
$targetDb = "WideWorldImportersNew3"
$outputReportFile = "report-$nowf-$targetDb.xml"
$outputReportPath = Join-Path $outputFolder $outputReportFile
$publishProfile = Join-Path -Path $dbpath -ChildPath "WideWorldImportersNew.publish.xml"
& $sqlpackage /Action:DeployReport `
/SourceFile:$dacpac /Profile:$publishProfile /TargetDatabaseName:$targetDb `
/OutputPath:$outputReportPath
#
# Generate SCRIPT as well
#
$nowf = Get-Date -Format "yyyyMMddTHHmmss"
$outputScriptFile = "script-$nowf-$targetDb.sql"
$outputScriptPath = Join-Path $outputFolder $outputScriptFile
& $sqlpackage /Action:Script `
/SourceFile:$dacpac /Profile:$publishProfile /TargetDatabaseName:$targetDb `
/OutputPath:$outputScriptPath