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

Add support for SQL DacPac. #1185

Merged
merged 1 commit into from
Mar 24, 2016
Merged
Show file tree
Hide file tree
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
29 changes: 29 additions & 0 deletions help/dacpac.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Packaging and Deploying SQL Databases

FAKE can be used to create a SQL DACPAC and also deploy it to a SQL Server using the MSDeploy executable. This is installed by default with Visual Studio and with the SQL Server Data Tools (SSDT) package.

DACPACs automatically diff from the source to the destination and generate the SQL script dynamically.

You can read up more on DACPac and MSDeploy arguments [here](https://msdn.microsoft.com/en-us/library/hh550081%28v=vs.103%29.aspx).

## Sample usage

Ensure that you have already built your database project (you can do this with standard MSBuild). Then, use the ``deployDb`` command to deploy the ``dbProject.dacpac`` to the ``myDatabase``.

open Fake.Sql.DacPac

/// the database for local development + compile
Target "DeployLocalDb" (fun _ ->
let connectionString = "Data Source=(localdb)\MSSQLLocalDB;Integrated Security=True;Database=MyDatabase;Pooling=False"
let dacPacPath = "path/to/dbProject.dacpac"
deployDb (fun args -> { args with Source = dacPacPath; Destination = localDbConnectionString }) |> ignore)

## Deployment Options

You can optionally specify the type of command to use (again, refer to the documentation above for more detail): -

* Deploy - full deploy to destination
* Script - SQL script
* Report - XML report of diff

In addition, you can also elect to deploy to Dacpac files rather than SQL databases - simply pass in the pass to the dacpac that you wish to generate.
1 change: 1 addition & 0 deletions help/literate/templates/template-project.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ <h3 class="muted">{project-name}</h3>
<li><a href="typescript.html">TypeScript support</a></li>
<li><a href="azurewebjobs.html">Azure WebJobs support</a></li>
<li><a href="azurecloudservices.html">Azure Cloud Services support</a></li>
<li><a href="dacpac.html">SQL DACPAC support</a></li>
<li><a href="fluentmigrator.html">FluentMigrator support</a></li>
<li><a href="androidpublisher.html">Android publisher</a></li>
<li><a href="watch.html">File Watcher</a></li>
Expand Down
1 change: 1 addition & 0 deletions src/app/FakeLib/FakeLib.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
<Compile Include="ChangeWatcher.fs" />
<Compile Include="CMake.fs" />
<None Include="app.config" />
<Compile Include="Sql.DacPac.fs" />
<Compile Include="RaygunHelper.fs" />
<Compile Include="SquirrelHelper.fs" />
<Compile Include="XCopyHelper.fs" />
Expand Down
42 changes: 42 additions & 0 deletions src/app/FakeLib/Sql.DacPac.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/// Contains helpers around deploying databases.
module Fake.Sql.DacPac

open Fake.EnvironmentHelper
open Fake.ProcessHelper

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

/// Configuration arguments for DacPac deploy
type DeployDbArgs = {
/// Type of action to execute. Defaults to Deploy.
Action : DeployAction
/// Path to source (path to DACPAC or Connection String).
Source : string
/// Path to destination (path to DACPAC or Connection String).
Destination : string
/// Timeout for deploy (defaults to 120 seconds).
Timeout : int
/// Block deployment if data loss can occur. Defaults to true.
BlockOnPossibleDataLoss : bool
/// Drops objects in the destination that do not exist in the source. Defaults to false.
DropObjectsNotInSource : bool }

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

/// Deploys a SQL DacPac or database to another database or DacPac.
let deployDb modifier =
let args = modifier defaultDeploymentArgs
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
WorkingDirectory = ""
Args = [] }