Download presentation
Presentation is loading. Please wait.
Published byRuth Lindsey Modified over 9 years ago
1
State-based or migration- based database development? A review of the pros and cons
3
SQL Relay Birmingham 29 th October 2014 @_AlexYates_ workingwithdevs.com uk.linkedin.com/in/alexanderyates alex.yates@red-gate.com
4
SQL Relay Newcastle 27 th October 2014 @_AlexYates_ workingwithdevs.com uk.linkedin.com/in/alexanderyates alex.yates@red-gate.com
5
SQL Relay Birmingham 29 th October 2014 @_AlexYates_ workingwithdevs.com uk.linkedin.com/in/alexanderyates alex.yates@red-gate.com
7
Reliability Safe deployments Fire prevention over firefighting Visibility Visualise pipeline Better coordination DevOps DBA + devs work together Automation Agility 12 3 Goals for project
11
V1V2
12
Migrations based solutions V1V2
13
State based solutions V1V2
15
“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
16
“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
17
Demo: the happy path! SOURCE CONTROL CONTINUOUS INTEGRATION AUTOMATED DEPLOYMENT
18
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
20
0124_edit_sproc.sql ALTER PROCEDURE myproc AS BEGIN SELECT col1, col2 FROM table_foo END
21
0124_edit_sproc.sql0125_table_rename.sql EXEC sp_rename 'table_foo', 'table_bar‘ ALTER PROCEDURE myproc AS BEGIN SELECT col1 FROM table_bar END ALTER PROCEDURE myproc AS BEGIN SELECT col1, col2 FROM table_foo END
22
0124_edit_sproc.sql0125_table_rename.sql EXEC sp_rename 'table_foo', 'table_bar‘ ALTER PROCEDURE myproc AS BEGIN SELECT col1 FROM table_bar END ALTER PROCEDURE myproc AS BEGIN SELECT col1, col2 FROM table_foo END !
23
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
24
V123 myproc.sql CREATE PROCEDURE myproc AS SELECT col1 FROM table_foo !
25
V123 myproc.sql CREATE PROCEDURE myproc AS SELECT col1 FROM table_foo V124 myproc.sql CREATE PROCEDURE myproc AS SELECT col1, col2 FROM table_foo
26
V123 myproc.sql CREATE PROCEDURE myproc AS SELECT col1 FROM table_foo V124 myproc.sql CREATE PROCEDURE myproc AS SELECT col1, col2 FROM table_foo V125 myproc.sql CREATE PROCEDURE myproc AS SELECT col1 FROM table_bar
27
V123 myproc.sql CREATE PROCEDURE myproc AS SELECT col1 FROM table_foo V124 myproc.sql CREATE PROCEDURE myproc AS SELECT col1, col2 FROM table_foo V125 myproc.sql CREATE PROCEDURE myproc AS SELECT col1 FROM table_bar !
29
REVISION 123REVISION 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
30
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
31
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
32
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
33
One more thing…
35
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?
36
State (+migrations) SSDT pre/post deploy scripts Redgate migrations Migrations (+state) ReadyRoll ‘deploy changes’ Best of both worlds?
38
Reliability Safe deployments Fire prevention over firefighting 1 Goals for project
40
Reliability Safe deployments Fire prevention over firefighting Visibility Visualise pipeline Better coordination 12 Goals for project
41
Reliability Safe deployments Fire prevention over firefighting Visibility Visualise pipeline Better coordination DevOps DBA + devs work together Automation Agility 12 3 Goals for project
43
@_AlexYates_ workingwithdevs.com/ delivering-databases-migrations-vs-state uk.linkedin.com/in/alexanderyates alex.yates@red-gate.com
44
Image sources AuthorSourceInformation ChiltepinsterWikimedia CommonsMocking Bird Argument.jpg – Wikimedia CommonsMocking 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”Creative CommonsAttribution-Share Alike 3.0 Unported TableatnyWikimedia CommonsAthlete at Starting block.jpg – Wikimedia CommonsAthlete at Starting block.jpg – Wikimedia Commons. This file is licensed under the Creative Commons Attribution 2.0 Generic license. Source on Wikimedia Commons: “BXP135671”Creative Commons Attribution 2.0 GenericBXP135671 Henry MühlpfordtFlickrCERN Atlas Control Room 2010-07-01 – FlickrCERN Atlas Control Room 2010-07-01 – Flickr. This file is licensed under the Creative Commons Attribution-ShareAlike 2.0 Generic license.Creative Commons Attribution-ShareAlike 2.0 Generic license Department for Business, Innovation and Skills FlickrToyota’s new Auris – FlickrToyota’s new Auris – Flickr. This file is licensed under the Creative Commons Attribution-NoDerivs 2.0 Generic license.Creative Commons Attribution-NoDerivs 2.0 Generic license Stephen WolfeFlickrViolinists – FlickrViolinists – Flickr. This file is licensed under the Creative Commons Attribution 2.0 Generic license.Creative Commons Attribution 2.0 Generic license Akira HsuFlickrThe Micro Four Thirds Logo by Empire Elite Stormtroopers - for the great “Micro Four Thirds Day” – FlickrThe 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.Creative Commons Attribution 2.0 Generic license Nils RinaldiFlickrHippo fight 2/3 – FlickrHippo fight 2/3 – Flickr. This file is licensed under the Creative Commons Attribution 2.0 Generic license.Creative Commons Attribution 2.0 Generic license My own collectionAll 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 I don’t always edit database. Content designed to be shared and delivered with credit to memegenerator.net. Ctrl.Alt.Designctrla.ltSocial Media share icons
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.