Skip to content

Instantly share code, notes, and snippets.

@LitKnd
Last active February 5, 2019 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LitKnd/274655e998efd6b7c8acae8107b711d5 to your computer and use it in GitHub Desktop.
Save LitKnd/274655e998efd6b7c8acae8107b711d5 to your computer and use it in GitHub Desktop.
param
(
[string]$project = 'C:\Users\kendar.DERP\Documents\Visual Studio 2017\Projects\BabbyNames2017\BabbyNames2017\BabbyNames2017.sqlproj',
[string]$packageVersion = '0.0.005',
[string]$packageID = 'BN',
[string]$buildArtifactPath = 'C:\DBAutomation\BuildArtifacts',
[string]$buildSQLServer = '.\DEV', # for named instance do '.\instancename'
[string]$releaseArtifactPath = 'C:\DBAutomation\ReleaseArtifacts',
[string]$targetSQLServer = '.\DEV',
[string]$targetDatabase = 'BabbyNamesNotQuiteEmpty',
[string]$sqlCompareOptions = '' #'ObjectExistenceChecks' #'NoTransactions'
)
$errorActionPreference = "stop"
# Invoke the build
$validatedProject = $project | Invoke-DatabaseBuild -TemporaryDatabaseServer "Data Source =$buildSQLServer"
# Create a database build artifact
$buildArtifact = $validatedProject | New-DatabaseBuildArtifact -PackageId $packageID -PackageVersion $packageVersion
# Export the build artifact
$buildArtifact | Export-DatabaseBuildArtifact -Path "$buildArtifactPath"
# We need to connect to the database we plan to deploy to to compare our build with its current state
$targetConnection = New-DatabaseConnection -ServerInstance $targetSQLServer -Database $targetDatabase
# Create the release artifact
$releaseArtifact = New-DatabaseReleaseArtifact -Source $buildArtifact -Target $targetConnection -SQLCompareOptions $sqlCompareOptions
# Export it to the file system for posterity
$releaseArtifact | Export-DatabaseReleaseArtifact -Path "$releaseArtifactPath\$targetDatabase\$packageID.$packageVersion\"
# Perform the deployment
Import-DatabaseReleaseArtifact -Path "$releaseArtifactPath\$targetDatabase\$packageID.$packageVersion\" | Use-DatabaseReleaseArtifact -DeployTo $targetConnection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment