DLM Automation

Use-DlmDatabaseRelease

Use-DlmDatabaseRelease

Uses the DatabaseRelease object produced by the New-DlmDatabaseRelease cmdlet to update a target database schema to match the source schema.

Syntax

Use-DlmDatabaseRelease [-InputObject] <DatabaseRelease> -DeployTo <DatabaseConnection> [-SkipPreUpdateSchemaCheck] [-SkipPostUpdateSchemaCheck] [-QueryBatchTimeout <int>] [<CommonParameters>]

Description

The Use-DlmDatabaseRelease cmdlet executes the SQL update script inside the database deployment resources produced by the New-DlmDatabaseReleaseCommand cmdlet. This updates the target database to the same state as the schema source specified in the DatabaseRelease object.

Before executing the script, DLM Automation first checks that the target database schema matches the target schema defined in the DatabaseRelease object. If the schemas don't match, DLM Automation will then check if the target database schema matches the source schema specified in the Use-DlmDatabaseRelease cmdlet. (This is to check if the update has already been applied and the target schema is already in the desired state). If these schemas also don't match, the cmdlet fails. If the checks show the target schema is already in the desired state, DLM Automation will skip running the SQL update script and the cmdlet will finish. To turn off these checks, use the SkipPreUpdateSchemaCheck parameter.

The Use-DlmDatabaseRelease cmdlet then executes the SQL script to update the target database. It logs any errors that occur in the execution, but will continue executing the whole script unless the connection to the database is broken (for example, if the database goes offline).

After executing the script, the cmdlet checks that the target database schema has updated correctly to the 'Source' schema specified in the New-DlmDatabaseRelease cmdlet. If the schema hasn't updated correctly, the cmdlet returns an error message. To turn off this check use the SkipPostUpdateSchemaCheck parameter.

By default, DLM Automation deploys static data contained in your NuGet package, scripts folder or zip file. The pre-update and post-update schema checks also check for differences in static data. To turn off the deployment of static data and to exclude static data from the schema checks, add IgnoreStaticData to the New-DlmDatabaseRelease command. For more information about static data, see http://www.red-gate.com/dlma/staticdata.

If the database deployment resources contain a filter, this will be applied to the pre-deployment and post-deployment schema checks; only differences between objects included by the filter will cause the check to fail. For more information about filters, see http://www.red-gate.com/dlma/filters.

The SQL Compare options specified in the DatabaseRelease object will be used in the schema comparison checks before and after running the update. For more information about SQL Compare options, see http://www.red-gate.com/dlma/compareoptions.

Parameters

-InputObject <RedGate.DLMAutomation.Compare.Domain.DatabaseRelease>

The Database Release to be deployed.

Aliases None
Required?true
Position?0
Default Value None
Accept Pipeline Inputtrue (ByValue)
Accept Wildcard Charactersfalse

-DeployTo <RedGate.DLMAutomation.Compare.SchemaSources.DatabaseConnection>

A Database Connection object or database connection string that identifies the target database to be updated. See New-DlmDatabaseConnection for details.

Aliases None
Required?true
Position?named
Default Value None
Accept Pipeline Inputfalse
Accept Wildcard Charactersfalse

-SkipPreUpdateSchemaCheck <System.Management.Automation.SwitchParameter>

Before running the update script, don't check that the target database has the correct schema or that the target database has already been updated.

Aliases None
Required?false
Position?named
Default ValueFalse
Accept Pipeline Inputfalse
Accept Wildcard Charactersfalse

-SkipPostUpdateSchemaCheck <System.Management.Automation.SwitchParameter>

Don't check that the target database has the correct schema after the update has run.

Aliases None
Required?false
Position?named
Default ValueFalse
Accept Pipeline Inputfalse
Accept Wildcard Charactersfalse

-QueryBatchTimeout <System.Int32>

The execution timeout, in seconds, for each batch of queries in the update script. The default value is 30 seconds. A value of zero indicates that no execution timeout will be enforced.

Aliases None
Required?false
Position?named
Default Value30
Accept Pipeline Inputfalse
Accept Wildcard Charactersfalse

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see http://technet.microsoft.com/en-us/library/hh847884.aspx.

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • RedGate.DLMAutomation.Compare.Domain.DatabaseRelease

    The Database Release to be deployed.

Return values

The output type is the type of the objects that the cmdlet emits.

  • None

Examples

---------- EXAMPLE 1 ----------

$staging = New-DlmDatabaseConnection -ServerInstance "staging01\sql2014" -Database "Staging" -Username "sa" -Password "P@ssw0rd"
$package = "C:\NuGetFeed\database.nupkg"

$update = New-DlmDatabaseRelease -Source $package -Target $staging

Use-DlmDatabaseRelease $update -DeployTo $staging

This example shows how to update a database to the schema contained in a NuGet package, database.nupkg.

The New-DlmDatabaseRelease cmdlet creates the database deployment resources. It uses the database, Staging, as the Target parameter: this is the schema to be updated. It uses a NuGet package containing a scripts folder, database.nupkg, as the Source parameter: this is the schema that Staging will be updated to.

The DatabaseRelease object, $update, is then passed to the Use-DlmDatabaseRelease cmdlet. This cmdlet runs the SQL update script contained in $update, which updates Staging to the schema contained in database.nupkg.

Before running the SQL update script, Use-DlmDatabaseRelease checks that Staging still has the same schema that it did at the time that $update was created. It then runs the script, and afterwards, checks that the update was successful and that Staging has the correct new schema.

If $package contains static data, DLM Automation will deploy it to the $staging database. The pre-deployment and post-deployment schema checks also check for differences in static data. To turn off the deployment of static data and to exclude static data from the schema checks, add the IgnoreStaticData parameter to New-DlmDatabaseRelease.

---------- EXAMPLE 2 ----------

$staging = New-DlmDatabaseConnection -ServerInstance "staging01\sql2014" -Database "Staging" -Username "sa" -Password "P@ssw0rd"
$package = "C:\NuGetFeed\database.nupkg"

$update = New-DlmDatabaseRelease -Source $package -Target $staging

Use-DlmDatabaseRelease $update -DeployTo $staging -SkipPostUpdateSchemaCheck

This example shows how to skip the post-deployment check that verifies the target database matches the source.

The Use-DlmDatabaseRelease cmdlet updates the database, Staging, to match the schema contained in the NuGet package, database.nupkg. The SkipPostUpdateSchemaCheck parameter is used to skip the post-update schema check.

---------- EXAMPLE 3 ----------

$staging = New-DlmDatabaseConnection -ServerInstance "staging01\sql2014" -Database "Staging" -Username "sa" -Password "P@ssw0rd"

Import-DlmDatabaseRelease -Path "C:\db\DatabaseRelease" | Use-DlmDatabaseRelease -DeployTo $staging

This example shows how to use the Import-DlmDatabaseRelease cmdlet to import the database deployment resources from a folder created previously by the Export-DlmDatabaseRelease cmdlet. The database, Staging, is updated to the schema specified by the DatabaseRelease object.


Didn't find what you were looking for?