30.06.2013 Views

SQL Server Team-based Development - Red Gate Software

SQL Server Team-based Development - Red Gate Software

SQL Server Team-based Development - Red Gate Software

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 4: Managing Deployments<br />

Function SqlDataCompare<br />

{<br />

param($<strong>Server</strong>1, $Database1, $<strong>Server</strong>2, $Database2)<br />

$Command = '&"C:\Program Files\<strong>Red</strong> <strong>Gate</strong>\<strong>SQL</strong> Data Compare 8\sqldatacompare.exe" /<br />

<strong>Server</strong>1:' + $<strong>Server</strong>1 + ' /database1:' + $Database1 + ' /server2:' + $<strong>Server</strong>2 + ' /<br />

database2:' + $Database2 + ' /synchronize'<br />

Invoke-Expression $Command<br />

}<br />

Listing 4-19: Synchronizing the data using PowerShell.<br />

The advantage of having these commands as methods is that you can store them in a<br />

PowerShell script file. That file can be included in any subsequent PowerShell script or at<br />

the interactive console, in order to perform the synchronization, as shown in Listing 4-20.<br />

.\SqlCompare.ps1<br />

SqlCompare '.' 'NorthwindDev' '(local)' 'Northwind'<br />

SqlDataCompare '.' 'NorthwindDev' '(local)' 'Northwind'<br />

The complete script used in this example can be found in the downloadable .zip file<br />

, as the file: <strong>SQL</strong>Compare.ps1<br />

Listing 4-20: Automating the synchronization.<br />

Automation with CruiseControl<br />

In addition to the techniques discussed, there are a few dedicated continuous integration<br />

tools and frameworks, which you might consider. Once such is CruiseControl.NET<br />

(http://sourceforge.net/projects/ccnet/).<br />

From the CruiseControl configuration file, we can use the <strong>SQL</strong> Compare command line<br />

to deploy the scripts folder held in the source control system to a real database. The full<br />

CruiseControl configuration file is included with the code download, but the key snippet<br />

is shown in Listing 4-21. It assumes the professional edition of <strong>SQL</strong> Compare, since using<br />

the command line and using a script folder are both professional features.<br />

124

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!