diff --git a/help/dacpac.md b/help/dacpac.md new file mode 100644 index 00000000000..d375247caa6 --- /dev/null +++ b/help/dacpac.md @@ -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. \ No newline at end of file diff --git a/help/literate/templates/template-project.html b/help/literate/templates/template-project.html index 12acaa8ea65..288a133e7fc 100644 --- a/help/literate/templates/template-project.html +++ b/help/literate/templates/template-project.html @@ -73,6 +73,7 @@

{project-name}

  • TypeScript support
  • Azure WebJobs support
  • Azure Cloud Services support
  • +
  • SQL DACPAC support
  • FluentMigrator support
  • Android publisher
  • File Watcher
  • diff --git a/src/app/FakeLib/FakeLib.fsproj b/src/app/FakeLib/FakeLib.fsproj index 107bbb71e21..1662d8bede2 100644 --- a/src/app/FakeLib/FakeLib.fsproj +++ b/src/app/FakeLib/FakeLib.fsproj @@ -169,6 +169,7 @@ + diff --git a/src/app/FakeLib/Sql.DacPac.fs b/src/app/FakeLib/Sql.DacPac.fs new file mode 100644 index 00000000000..d7ab4ee9cb8 --- /dev/null +++ b/src/app/FakeLib/Sql.DacPac.fs @@ -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 = [] } +