You are ahead of the curve. You’ve learned that you need to put your database in source control and you’ve set up some sort of automated build and regression testing process. (Or you’ve been to my continuous integration session.)
However, your deployments are still expensive and risky. You find it hard to keep track of what has been deployed to each environment. You don’t have a great deal of confidence that the production database is still in line with source control. You may have heard of the automated deployment functionality in VSTS or Octopus Deploy but you haven’t tried it yet… at least not for SQL Server.
In this session I’ll automate a deployment pipeline in a couple of different ways. I’ll discuss the importance of your database model as well as repeatable upgrade scripts and discuss the pros and cons of different approaches to automation. I’ll also discuss how to monitor for and protect yourself from database drift.
8. @_AlexYates_
#SqlSatIceland
Farm Credit Services of America (FCSA)
• 100 person IT team, 14 sub-teams
• Database version control inconsistent
• Deployment process manual
• Delivery was slow and unreliable
9. @_AlexYates_
#SqlSatIceland
Farm Credit Services of America (FCSA)
• Growing test suite
• Delivery faster and more reliable by
catching issues early
• Standardised source control process
• Automated builds/deploys from source control
11. @_AlexYates_
#SqlSatIceland
Databases are hard
• Schema changes vs existing data
• Reference data vs production data
• Teamwork and testing
• Database drift (change outside
process, e.g. production hot-fixes)
30. @_AlexYates_
#SqlSatIceland
“There's nothing more
reliable than keeping
track of exactly the
scripts you intend to run,
and running them, without
trying to compare model
and guess.”
Paul Stovell,
built Octopus Deploy
http://docs.octopusdeploy.com/display/OD/SQL+Server+databases
@_AlexYates_
#SqlSatIceland
31. @_AlexYates_
#SqlSatIceland
“As soon as you have
multiple changes on a
single aspect of an object,
ordering and the ability to
detect which change
needs to be made gets
very complicated.”
@_AlexYates_
#SqlSatIceland
32. @_AlexYates_
#SqlSatIceland
“As soon as you have
multiple changes on a
single aspect of an object,
ordering and the ability to
detect which change
needs to be made gets
very complicated.”
Gert Drapers,
built DataDude
https://blogs.msdn.microsoft.com/gertd/2009/06/05/declarative-database-development/
@_AlexYates_
#SqlSatIceland
40. @_AlexYates_
#SqlSatIceland
Model
Easier (less control)
Better for sprocs/functions
Better for large/distributed
teams
Better for frequent changes
Better for dependency
nightmares
Drift: rolled back
Better for development
Migrations
More control (harder/needs
discipline)
Better for data migrations
Better for small teams
Better for infrequent
changes
Better for simple data stores
Drift: ignored
Better for automation
VS
47. @_AlexYates_
#SqlSatIceland
What is CI?
Continuous Integration (CI) is a development practice that
requires developers to integrate code into a shared repository
several times a day.
Each check-in is then verified by an automated build, allowing
teams to detect problems early.
www.thoughtworks.com/continuous-integration
56. @_AlexYates_
#SqlSatIceland
What is CD?
Continuous Delivery (CD) is the natural extension of
Continuous Integration: an approach in which teams ensure
that every change to the system is releasable, and that we can
release any version at the push of a button.
Continuous Delivery aims to make releases boring, so we can
deliver frequently and get fast feedback on what users care
about.
www.thoughtworks.com/continuous-delivery
64. @_AlexYates_
#SqlSatIceland
What do you really need to deploy with
confidence?
1. Source model
2. Target model
Replacing a single deployment script with a credible release
65. @_AlexYates_
#SqlSatIceland
What do you really need to deploy with
confidence?
1. Source model
2. Target model
3. Upgrade script
Replacing a single deployment script with a credible release
66. @_AlexYates_
#SqlSatIceland
What do you really need to deploy with
confidence?
1. Source model
2. Target model
3. Upgrade script
4. Change report
SELECT ContactsID,
ContactFullName,
Address1,
CountryCode,
Replacing a single deployment script with a credible release
72. @_AlexYates_
#SqlSatIceland
What should happen if anything goes wrong?
1. If target doesn’t match target model (or source model) – error and
abort
2. If script fails – roll back transaction
3. If target doesn’t match source model after script execution – do
not roll back but send warning, then roll-forward
79. @_AlexYates_
#SqlSatIceland
Deployments
are run on
RM agents
Deployments
are managed on
RM server
RM
server
How do release management tools work?
Builds/Tests
are run on
CI agents
Builds/Tests
are managed on
CI server
CI
server
Just like a CI server!
93. @_AlexYates_
#SqlSatIceland
In summary
• Install the release management server on a test server or
build server etc
• Install agents that will deploy applications on the application
servers themselves
• Install agents that will deploy databases on a machine that
has access to your target databases
• Install DB deployment tool on the same machine as the
agent that you will use to deploy your databases
106. @_AlexYates_
#SqlSatIceland
• Standardised VCS, CI and RM processes
• FCSA delivering much more efficiently
• FCSA process model for sister organisations
• The team all have excellent CV’s
Farm Credit Services of America (FCSA)
107. @_AlexYates_
#SqlSatIceland
• Standardised VCS, CI and RM processes
• FCSA delivering much more efficiently
• FCSA process model for sister organisations
• The team all have excellent CV’s
Farm Credit Services of America (FCSA)
http://www.codeaperture.io/2016/09/13/how-redgate-helped-define-our-process/
111. @_AlexYates_
#SqlSatIceland
Model
Easier (less control)
Better for sprocs/functions
Better for large/distributed
teams
Better for frequent changes
Better for dependency
nightmares
Drift: rolled back
Better for development
Migrations
More control (harder/needs
discipline)
Better for data migrations
Better for small teams
Better for infrequent
changes
Better for simple data stores
Drift: ignored
Better for automation
VS
Clever people consider options …
116. @_AlexYates_
#SqlSatIceland
Takk fyrir að koma á SQL Saturday Iceland
Sérstakar þakkir til styrktaraðila
SQL SATURDAY | #602 | REYKJAVIK 2017
http://www.sqlsaturday.com/602/Sessions/SessionEvaluation.aspx
119. @_AlexYates_
#SqlSatIceland
Image sources
Author Source Information
Chiltepinster Wikimedia Commons Mocking Bird Argument.jpg – Wikimedia Commons. This file is licensed under the Creative Commons Attribution-Share
Alike 3.0 Unported license. Source on Wikimedia Commons: “Own work”
Bit Boy Flickr The elephant in the room – Flickr. This file is licensed under the Creative Commons Attribution 2.0 Generic license.
Nils Rinaldi Flickr Hippo fight 2/3 – Flickr. This file is licensed under the Creative Commons Attribution 2.0 Generic license.
My own collection Taken by/property of Alex Yates Kitten, “There’s more than one way to skin a cat!”
Memegenerator.net Memegenerator.net I don’t always edit database. Content designed to be shared and delivered with credit to memegenerator.net.
Ctrl.Alt.Design ctrla.lt Social Media share icons