21. “There's nothing more reliable
than keeping track of exactly the
scripts you intend to run, and
running them, without trying to
compare state and guess.”
Paul Stovell, built Octopus Deploy
22. “There's nothing more reliable
than keeping track of exactly the
scripts you intend to run, and
running them, without trying to
compare state and guess.”
Paul Stovell, built Octopus Deploy
“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
23. Demo: the happy path!
SOURCE
CONTROL
CONTINUOUS
INTEGRATION
AUTOMATED
DEPLOYMENT
24. 11
2 Table rename
Table ‘foo’ is to be renamed ‘bar’
Edit stored procedure
Myproc to select col2 from table ‘foo’
(currently it selects only col1)
Task
29. Conflicts easily missed
Changes overwritten
Order matters
Last script wins
To review changes
Much reading, but very
important to get code right
The problem with migrations
35. REVISION 123 REVISION 124
table_foo.sql
CREATE TABLE table_foo
(col1 NVARCHAR(max), col2
NVARCHAR(max))
myproc.sql
CREATE PROCEDURE myproc
AS
SELECT col1
FROM table_foo
table_bar.sql
CREATE TABLE table_bar
(col1 NVARCHAR(max), col2
NVARCHAR(max))
myproc.sql
CREATE PROCEDURE myproc
AS
SELECT col1, col2
FROM table_bar
36. Diff script:
DROP TABLE table_foo
CREATE TABLE table_bar
(col1 NVARCHAR(max), col2
NVARCHAR(max))
ALTER PROCEDURE myproc
AS
SELECT col1, col2 FROM table_bar
The problem with state
37. Diff script
DROP TABLE table_foo
CREATE TABLE table_bar
(col1 NVARCHAR(max), col2
NVARCHAR(max))
ALTER PROCEDURE myproc
AS
SELECT col1, col2 FROM table_bar
!
The problem with state
38. Script
DROP TABLE table_foo
CREATE TABLE table_bar
(col1 NVARCHAR(max),
col2 NVARCHAR(max))
ALTER PROCEDURE myproc
AS
SELECT col1, col2
FROM table_bar
Need to understand your tool
It should be obvious to you that
your tool won’t work
What is the Plan B / override?
Because one day you’ll need it
Test for data loss
Automatically (naturally)
The problem with state
41. State
Easier (less control)
Better for sprocs/functions
Better for large/distributed teams
Better for frequent changes
Better for dependency nightmares
Drift: rolled back
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
So what is better?
42. State (+migrations)
SSDT pre/post deploy scripts
Redgate migrations
Migrations (+state)
ReadyRoll ‘deploy changes’
Best of both worlds?
50. 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”
Tableatny Wikimedia Commons Athlete at Starting block.jpg – Wikimedia Commons. This file is licensed under the Creative Commons Attribution 2.0
Generic license. Source on Wikimedia Commons: “BXP135671”
Henry Mühlpfordt Flickr CERN Atlas Control Room 2010-07-01 – Flickr. This file is licensed under the Creative Commons Attribution-ShareAlike 2.0
Generic license.
Department for Business,
Innovation and Skills
Flickr Toyota’s new Auris – Flickr. This file is licensed under the Creative Commons Attribution-NoDerivs 2.0 Generic license.
Stephen Wolfe Flickr Violinists – Flickr. This file is licensed under the Creative Commons Attribution 2.0 Generic license.
Akira Hsu Flickr The Micro Four Thirds Logo by Empire Elite Stormtroopers - for the great “Micro Four Thirds Day” – 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 All pictures are either of me,
taken by friends/colleagues, or
taken by me
All pictures on about me slide, including kitten, and team at Farm Credit Services of America (FCSA). FCSA have allowed
me/Redgate to reference the visit in presentations/marketing material etc.
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
Notas del editor
You may have seen a similar talk with a similar name at NDC London. I’ve spoken with Enrico and I agree there is an elephant we need to discuss. I’m going to approach the subject in a similar but different way.
Show of hands:
For your apps, who uses VCS?
CI?
Who has an automated deployment pipeline?
Now groan or cheer – is it a good thing?
Keep your hands up if you do the same for the database?
NEW SLIDE
In my experience the database holds people back…
My name is Alex etc
Now – who has read a book about programming in the last two decades?
Did it have these words in it?
NEXT SLIDE
Show of hands… Who is a developer? Project manager?
Do we have any DBAs?
DBAs care about… NEXT SLIDE
DBAs care about this stuff.
Two buisness entities with different goals. It causes friction.
NEXT SLIDE
Who has separate teams of DBAs and developers?
And things get really stressful when deployments fail.
Sometimes DEV fail
Sometimes OPS fail
Think about it as a continuous pipeline – you are both responsible for different parts
You need to work together on hand-offs
An example of everyone working together
Lets take a closer look at that diagram
Let’s make it a little clearer
Now there are various ways to solve this problem…
There’s normally more than one way to skin a cat. Database CD is the same.
Fundamentally this is our problem with databases - get from one state to another.
With apps you don’t need to worry about the transition, with databases you do.
NEXT SLIDE…
This leads some to think about database migrations in terms of the upgrade scripts…
Migrations based solutions like Dbup, FlyWay, DbDeploy and ReadyRoll.
NEXT SLIDE…
Other people still see the value/need to consider the state. This is important for repeatable testing etc.
Migrations become a deployment detail because some would argue that scripting out every minor change is an overhead and opens up possibility of human error.
NEXT SLIDE…
People get really passionate about one solution or the other.
It’s become a really hot and polarised debate. I’m calling for people on both sides to be more open minded.
Who here has seen Seb Rose’s lightning talk about passionate developers? Well worth a watch!
NEXT SLIDE…
NEXT SLIDE…
NEXT SLIDE…
For example, Paul Stovell basically says the migrations approach is reliable and provides the functionality to handle the deployment whatever way works.
Bert Gert Drapers from Microsoft points out that the state based solutions tend to be more practical and easier to implement in practice.
Some would say that migrations is the powerful option while state is the easy option.
With migrations you have to maintain many upgrade scripts.
Strength: Complete control. Power and responsibility.
Weakness: Challenge to manage. Winding path.
With migrations you have to maintain many upgrade scripts.
Strength: Complete control. Power and responsibility.
Weakness: Challenge to manage. Winding path.
Although we’ve done a rename, it’s evident only by examining the before and after states. The migrations approach show how the change is made, but doesn’t have knowledge about the before and after states.
An example of everyone working together
An example of everyone working together
An example of everyone working together
By adopting a CD process for the DB the DBA is involved earlier.
He can review code in source control before it goes anywhere near production.
Reviewing deployments becomes less about QA and more about timing deployments appropriately and double checking for any red flags.