Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DACPAC module. #1306

Merged
merged 1 commit into from
Jul 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/app/FakeLib/Sql.DacPac.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ open Fake.ProcessHelper

/// The type of action to execute.
type DeployAction =
/// Generate and apply a synchronisation between two databases.
/// Generate and apply a synchronisation script between two databases.
| Deploy
/// Generate a SQL script to sync two databases.
| Script
| Script of OutputPath:string
/// Generate an XML report for the differences between two databases.
| Report
| Report of OutputPath:string

/// Configuration arguments for DacPac deploy
type DeployDbArgs = {
Expand All @@ -31,12 +31,25 @@ type DeployDbArgs = {
/// The default DacPac deployment arguments.
let defaultDeploymentArgs = { Action = Deploy; Source = ""; Destination = ""; Timeout = 120; BlockOnPossibleDataLoss = true; DropObjectsNotInSource = false }

let private generateCommandLine args =
let action, outputPath =
match args with
| Deploy -> "Publish", None
| Script outputPath -> "Script", Some outputPath
| Report outputPath -> "DeployReport", Some outputPath
let outputPath = defaultArg(outputPath |> Option.map(sprintf """/OutputPath:"%s" """)) ""
action, outputPath

/// Deploys a SQL DacPac or database to another database or DacPac.
let deployDb modifier =
let args = modifier defaultDeploymentArgs
let action, outputPath = generateCommandLine args.Action
shellExec {
Program = sprintf @"%s\IIS\Microsoft Web Deploy V3\MSDeploy.exe" ProgramFiles
CommandLine = sprintf """-verb:sync -source:dbDacFx="%s" -dest:dbDacFx="%s",DacPacAction=%A,BlockOnPossibleDataLoss=%b,DropObjectsNotInSource=%b,CommandTimeout=%d""" args.Source args.Destination args.Action args.BlockOnPossibleDataLoss args.DropObjectsNotInSource args.Timeout
Program = sprintf @"%s\Microsoft SQL Server\130\DAC\bin\SqlPackage.exe" ProgramFilesX86
CommandLine = sprintf """/Action:%s /SourceFile:"%s" /TargetConnectionString:"%s" %s /p:BlockOnPossibleDataLoss=%b /p:DropObjectsNotInSource=%b /p:CommandTimeout=%d""" action args.Source args.Destination outputPath args.BlockOnPossibleDataLoss args.DropObjectsNotInSource args.Timeout
WorkingDirectory = ""
Args = [] }
|> function
| 0 -> ()
| _ -> failwith "Error executing DACPAC deployment. Please see output for error details."