microsoft sql server continuous integration
DESCRIPTION
Presenter: Ernest Hwang of Practice Fusion > This presentation shows how to simplify your database deployments, ensure that no database changes are overlooked, and implement unit tests using the suite of Red Gate developer tools. You'll see how Practice Fusion streamlines database deployments in their Integration, Testing, Staging, and Production environments. This frees developers from the burden of maintaining deployment scripts, while reducing the number of overlooked breaking changes to zero. The demo uses a Windows Azure box as the Jenkins (Continuous Integration) server and several SQL Azure databases (representing Integration and QA environments). The entire repository is hosted on GitHub (https://github.com/CF9/Databases.RGDemo), for anyone to download. You'll learn how to: * Add your database to source control in under five minutes * Create a CI Job to validate your database “build” * Deploy database changes to your environments with a mouse click * Set up database unit testing using tSQLt * Avoid problems when implementing Database CI in the “real-world” Ernest Hwang is a Principal Software Engineer at Practice Fusion in San Francisco. He uses Red Gate SQL Source Control, SQL Compare, SQL Data Compare, and SQL Test to automate Practice Fusion's Continuous Integration efforts and instrument database deployments.TRANSCRIPT
![Page 1: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/1.jpg)
SQL Server ContinuousIntegration
Using Jenkins and Red Gate
Ernest HwangPrincipal Software Engineer, Practice Fusion
Presented to the
Silicon Valley SQL Server User Group
May 2013
![Page 2: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/2.jpg)
Who am I?
• Ernest Hwang, Principal Software Engineerat Practice Fusion in San Francisco
• C#, .NET, SQL Server Developer
• Working with SQL Server since 1999 (SQL Server 6.x)
• Using Red Gate for Continuous Integration since June2011
• Someone who got tired of maintaining a folder ofdatabase scripts for every release.
![Page 3: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/3.jpg)
Why am I here?
• To show how easy it is to apply CI principals toDatabase Development
![Page 4: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/4.jpg)
What’s this?
A “How To” guide for automating your day-to-daymaintenance tasks by…
• *Easily* Versioning your database using Red Gate SQL SourceControl
• Using Continuous Integration (via Jenkins) to validateDatabase builds
• Using Jenkins to automate database deployments
• Using CI / tSQLt / SQL Test to run unit tests
![Page 5: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/5.jpg)
Prerequisites
• Experience with source control management systems(svn, TFS, git, Hg)
• Familiarity with Continuous Integration Products(Jenkins, Team City, Cruise Control)
• Awareness of build scripting languages (ant,MSBuild)
![Page 6: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/6.jpg)
What software is used?
• SQL Server 2008 / 2012
• Red Gate SQL Source Control
• Red Gate SQL Compare
• Red Gate SQL Data Compare
• Jenkins Continuous Integration Serverhttp://jenkins-ci.org/
– Promoted Build Plugin
– Copy Artifacts Plugin
– Version Plugin
– Git Plugin
• MSBuild
![Page 7: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/7.jpg)
What is SQL Source Control?
• Source Control Plug in for SQL Server ManagementStudio
• Creates a “snapshot” of the database schema defined byCREATE scripts
• Snapshot is consumable by SQL Compare and may beused to compare against the schema of an actualdatabase
![Page 8: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/8.jpg)
What is SQL Source Control?
SQL Source Control is to SSMSas
TortoiseSVN is to Windows Explorer
![Page 9: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/9.jpg)
Demo Environment
GitHub
Local Copy ofRGDemo database
Dev, QA, & ProdDatabases
Developer Workstation
Build and Database Server(Windows Azure VM)
![Page 10: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/10.jpg)
Committing Changes to SourceControl
Demo
Local DatabaseChanges
Commit Changesvia SQL Source
Control
Changes committed toSCM repository
![Page 11: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/11.jpg)
How does Continuous Integration fitin?
• The CI server polls the repository for changes
• When changes are checked in, the CI job kicks off
– Verifies that the database can be built
• Builds a brand new database from scratch using SQLCompare and SQL Data Compare
– Runs unit tests
• Build should fail if unit tests do not succeed
– Archives the artifacts (for deployments)
• Artifacts can include build/test reports
– Emails engineers if there are problems
![Page 12: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/12.jpg)
Breaking the Build
Demo
Commit Changesvia SQL Source
Control
CI Server Detects ChangesKicks off Build Process
Build can pass orfail validation
![Page 13: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/13.jpg)
Deploying Changes to DifferentEnvironments
• The Promoted Builds plug in can be used to deploychanges to Integration/QA/Staging/Productionenvironments
• SQL Compare and SQL Data Compare are used todeploy changes between the sourced controlleddatabase and your development environments
• Deploying to Production and/or Staging can beconfigured to just create the scripts as opposed toforcing the synchronization
![Page 14: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/14.jpg)
Deploying to Dev / QA
Demo
SQL Source ControlRepository
SQL Compare Development EnvironmentDatabase
![Page 15: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/15.jpg)
Creating a Database “Version”
• Make sure the Jenkins Versioning plugin is installed
• Create a User Defined Function calleddbo.DATABASE_VERSION()
• Create a build step that updates the UDF with theversion number
• The updated UDF will be archived and used withdeployments
![Page 16: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/16.jpg)
Versioning your Database
Demo
Commit Changesvia SQL Source
Control
CI Server DetectsChanges
Kicks off BuildProcess
Build Task updatesdbo.DATABASE_VERSION()
Function
Updated UDFArchived
![Page 17: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/17.jpg)
Unit Testing with tSQLt and SQL Test
• tSQLt is an open source set of stored procedures andfunctions to facilitate Unit Testing in SQL databases
• SQL Test is a wrapper around this framework thatintegrates with SSMS
• Your build server can enforce that your unit tests passand generate reports
![Page 18: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/18.jpg)
Unit Testing with tSQLt / SQL Test
Demo
Commit Changesvia SQL Source
Control
CI Server DetectsChanges
Kicks off BuildProcess
Build Task executesUnit Test procedures
Tests can pass orfail the build
![Page 19: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/19.jpg)
What did SQL Source Control do for us?
• Saves developers time (yay!)
– No more maintaining update scripts
– Don’t need to deploy scripts when QA needs changes
• Identifies holes in your deployment process
– Are developers making changes directly toproduction?
– Are indexes/constraints missing from yourDev/QA/Prod environments?
• Creates a definitive database build that can be easilydeployed and redeployed
![Page 20: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/20.jpg)
Considerations
• Environments must be pristine
• Process must be changed and understood
• Production change scripts should be scrutinized(especially for the first few releases)
• Migration Scripts can be used to massage data
• DB Replication requires more work for promotions
![Page 21: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/21.jpg)
Appendix 1: Other CI Servers
• Jenkins (open source)
• Team City (JetBrains)
• Bamboo (Atlassian)
• CruiseControl / CruiseControl.NET (open source)
![Page 22: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/22.jpg)
Appendix 2: Other Source ControlSystems
• Subversion (SVN)
• Git
• Team Foundation Server
• Mercurial (Hg)
• AccuRev
• Surround SCM
![Page 23: Microsoft SQL Server Continuous Integration](https://reader035.vdocuments.net/reader035/viewer/2022062303/55526ceab4c905d41d8b518b/html5/thumbnails/23.jpg)
Links / Contact Info• [email protected]
• @ernestedcode
• https://github.com/CF9/Databases.RGDemo
• Practice Fusion is Hiring (email me)http://practicefusion.com/careers/
• facebook.com/practicefusion
• @practicefusion