Skip to content

Azure Reversal Release Pipeline Example

The DataStar scripts encapsulate data and their related entities as a scriptable component. When these components are deployed they make the necessary changes to the target environment by inserting, updating and deleting records. This idea of encapsulating data as a component also facilitates DataStar to be able to automatically generate the scripts necessary to reverse the changes so that the data can be reverted to it's original state. The reversal feature enables the generation of reversal or rollback scripts at the time of deployment so that if necessary the changes can be reverted.

To take full advantage of the DataStar Reversal feature you should automate the build and deployment of the database scripts. DataStar comes with all the necessary components to incorporate DataStar into "Dev Ops" so that you can fully automate and audit your deployments. It is recommended that you either:

  • Configure the deployment pipeline to generate the reversal scripts as a NuGet Package or Zipped File and store this in an artifacts repository, or
  • Implement the Audit and History tables to store the deployment logs and hold the generated reversal scripts.

In this example it assumes that you are using the Audit tables to capture the reversal scripts as part of your release pipeline, there are some examples for Octopus that show how you can publish the reversal scripts as NuGet packages.

Step 1

Deploy the latest version of DataStar.Tools to your artifacts repository and set it as a dependency so that it is pulled in when the pipeline executes. This is the only dependency that needs to be set as the scripts to execute will be obtained from the database.

Step 2

Add a command line step to extract the scripts from the database a number of variables are required as shown below (note the -cn "reversal" flag)

DataStar.Tools.exe -db "Microsoft" -en "DEV" -cs "User ID=$(DatabaseUser);Password=$(DatabasePassword);Data Source=$(DataSource);Database=$(Database)" -ae -ah "ADS_DEPLOYMENT_HISTORY" -ar "ADS_DEPLOYMENT_REVERSAL" -as "ADS_DEPLOYMENT_SUMMARY" -wi "$(WorkItem)" -cn "reversal" -od "$(System.ArtifactsDirectory)\Reversal"

In this example a work item is specified which means the latest reversal package for that work item will be selected, if preferred you can specify the -id with the identifier of the audit history record to be reversed. When this step executes it will generate a reversal.json file in the output directory with some metadata that will be required in subsequent steps (see example below).

{"WorkItem":"33","VersionNumber":1,"AuditHistoryId":12,"ArtifactName":"33-001"}

Step 3

The reversal.json file needs to be processed so that the variables are available in the pipeline, you can use the Azure Marketplace "DataStar Set Json Parameters Utility" to load the variables in the file.

Step 4

The next step is to run the scripts that were extracted in step 2, see the example below:

DataStar.Tools.exe -db "Microsoft" -en "DEV" -cs "User ID=$(DatabaseUser);Password=$(DatabasePassword);Data Source=$(DataSource);Database=$(Database)" -ae -ah "ADS_DEPLOYMENT_HISTORY" -ar "ADS_DEPLOYMENT_REVERSAL" -as "ADS_DEPLOYMENT_SUMMARY" -wi "$(WorkItem)" -vn "$(VersionNumber)" -wd "$(System.ArtifactsDirectory)\Reversal" -lf "output.txt" -ri "$(AuditHistoryId)"

It is important to specify the -ri "$(AuditHistoryId)" option so that the audit history table gets updated with audit entry that it is reversing.

Step 5

Add additional steps as required such as updating the work item history with the details of the reversal.

Client Setup

Please refer to the Getting Started section on the Reversal Feature.