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. #1307

Merged
merged 5 commits into from
Jul 20, 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
22 changes: 19 additions & 3 deletions src/app/FakeLib/Sql.DacPac.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Fake.Sql.DacPac

open Fake.EnvironmentHelper
open Fake.ProcessHelper
open System.IO

/// The type of action to execute.
type DeployAction =
Expand All @@ -15,6 +16,8 @@ type DeployAction =

/// Configuration arguments for DacPac deploy
type DeployDbArgs = {
/// The path to SqlPackage.exe. If none is supplied, a set of default locations will be probed.
SqlPackagePath : string option
/// Type of action to execute. Defaults to Deploy.
Action : DeployAction
/// Path to source (path to DACPAC or Connection String).
Expand All @@ -29,7 +32,7 @@ type DeployDbArgs = {
DropObjectsNotInSource : bool }

/// The default DacPac deployment arguments.
let defaultDeploymentArgs = { Action = Deploy; Source = ""; Destination = ""; Timeout = 120; BlockOnPossibleDataLoss = true; DropObjectsNotInSource = false }
let defaultDeploymentArgs = { SqlPackagePath = None; Action = Deploy; Source = ""; Destination = ""; Timeout = 120; BlockOnPossibleDataLoss = true; DropObjectsNotInSource = false }

let private generateCommandLine args =
let action, outputPath =
Expand All @@ -44,8 +47,21 @@ let private generateCommandLine args =
let deployDb modifier =
let args = modifier defaultDeploymentArgs
let action, outputPath = generateCommandLine args.Action
shellExec {
Program = sprintf @"%s\Microsoft SQL Server\130\DAC\bin\SqlPackage.exe" ProgramFilesX86

let pathsToCheck =
(args.SqlPackagePath |> Option.toList) @
[ ProgramFilesX86 </> @"Microsoft SQL Server\130\DAC\bin\SqlPackage.exe"
ProgramFilesX86 </> @"Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\130\SqlPackage.exe" ]

let sqlPackagePath =
pathsToCheck
|> List.tryFind File.Exists
|> function
| Some path -> path
| None -> failwith (sprintf "Unable to find a valid instance of SqlPackage.exe. Paths checked were: %A." pathsToCheck)

shellExec {
Program = sqlPackagePath
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 = [] }
Expand Down