getting ci right for sql server

92
@_AlexYate s_ #SQLLeeds Getting CI right for SQL Server Alex Yates

Upload: alex-yates

Post on 12-Apr-2017

49 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Getting CI right for SQL Server

Alex Yates

Page 2: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

DLM Consultant

workingwithdevs.com

[email protected]

Alex Yates

@_AlexYates_

Page 3: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

@_AlexYates_ | #SQLLeeds

Page 4: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

AgileScrumLeanDevOpsIterativeContinuous Delivery

Developers

Page 5: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

MonitoringDeployment

IntegrityPerformance

DBAs

Page 7: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Woah! Deployment fail?

Page 8: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

#worksOnMyMachine

Woah! Deployment fail?

Page 9: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

A cursor?! You just CAN’T do that?!

Page 10: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

#worksOnMyMachine

A cursor?! You just CAN’T do that?!

Page 11: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Hey, you just dropped my hot-fix!

Page 12: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

#worksOnMyMachine

Hey, you just dropped my hot-fix!

Page 13: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

What is CI?

Page 14: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

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

Page 15: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

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

Page 16: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Farm Credit Services of America (FCSA)

• Deployments easier to review• Delivery faster and more

reliable

• Standardised source control and delivery process

• Automated manual deployment tasks

Page 17: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

The deployment pipeline

Page 18: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

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)

Page 19: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

The deployment pipeline

Page 20: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 21: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 22: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Version Control

Page 23: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Version control - LMGTFY

Page 24: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 25: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 26: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

There’s more than one way to skin a cat

Page 27: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

There’s more than one way to skin automatea cat

Page 28: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

V1 V2

Page 29: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

V1 V2

Migrations-based solutions

Page 30: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

V1 V2

State-based solutions

Page 31: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Page 32: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

“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.”

Page 33: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

“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

http://docs.octopusdeploy.com/display/OD/SQL+Server+databases

Page 34: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

“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.”

Page 35: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

“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/

Page 36: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Migrations vs state

http://workingwithdevs.com/delivering-databases-migrations-vs-state/

Page 37: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Migrations vs state

http://workingwithdevs.com/delivering-databases-migrations-vs-state/

Page 38: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Migrations vs state

http://workingwithdevs.com/delivering-databases-migrations-vs-state/

Page 39: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Migrations vs state

http://workingwithdevs.com/delivering-databases-migrations-vs-state/

Page 40: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Migrations vs state

http://workingwithdevs.com/delivering-databases-migrations-vs-state/

Page 41: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Migrations vs state

http://workingwithdevs.com/delivering-databases-migrations-vs-state/

Page 42: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Migrations vs state

http://workingwithdevs.com/delivering-databases-migrations-vs-state/

Page 43: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

State 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

Page 44: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

DLMConsultants.com/model-vs-mig

Page 45: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Demo

Page 46: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 47: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 48: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Automated builds

Page 49: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

VCS Build Test Sync

Upgrade scriptDatabase package

Test results

The automated build process

Page 50: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

http://www.jamesshore.com/Blog/Continuous-Integration-on-a-Dollar-a-Day.html

Page 51: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Build servers

Page 52: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Builds/Tests are run on CI agents

Builds/Tests are managed on

CI server

CI server

How do build servers work?

Page 53: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Demo

Page 54: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 55: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 56: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Unit testing

Page 57: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Unit testing

www.tsqlt.org

Page 58: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Unit testing

www.tsqlt.org

Page 59: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Unit testing

www.tsqlt.org

Page 60: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

www.tsqlt.org

Unit testing

Page 61: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Unit testing

Page 62: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Unit testing

Page 63: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

http://workingwithdevs.com/three-odd-attitudes-towards-database-unit-testing-that-make-me-angry/

Page 64: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Demo

Page 65: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 66: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 67: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Drift

Page 68: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Page 69: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

“When making changes directly on production, you are making a decision that the delay due to poor cycle time is more expensive than the risk of making a mistake.”

Page 70: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

“When making changes directly on production, you are making a decision that the delay due to poor cycle time is more expensive than the risk of making a mistake.”

Alex Yates, built this slide

Page 71: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

The bad stuff:

• Accidental roll-backs (state)

• Failed deployments (migrations)

• Environment inconsistency (migrations)

Page 72: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

DriftStrategies to help

Improve cycle time Strict security policies Monitor drift (play with DDL

triggers) Redgate DLM Dashboard

(free)https://www.simple-talk.com/sql/database-administration/database-deployment-the-bits-database-version-drift/

Page 73: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

DriftStrategies to help

Improve cycle time Strict security policies Monitor drift (play with DDL

triggers) Redgate DLM Dashboard

(free)http://www.red-gate.com/products/dlm/dlm-dashboard/

Page 74: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Demo

Page 75: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 76: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 77: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

• Don’t do *all the things* at once - start with VCS and drift, then CI, then RM• Don’t forget tests• Teamwork above tools/process• Keep Branching simple… especially if you aren’t using a DVCS• Decouple database deployments from other systems

• Use the right process/tool for your database and team

• Ask me for help!

General advice

Page 78: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 79: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

• 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)

Page 80: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

• 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/

Page 81: Getting CI right for SQL Server
Page 82: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Siloed sparrows suck at DLM

Page 83: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Heated hippos are closed minded

Page 84: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

State 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

Page 85: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Use appropriate tools

Page 86: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Only hire developers who write tests

Page 87: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Hunt his smug face - make pain on it

Page 88: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

This stuff makes a big difference

http://www.codeaperture.io/2016/09/13/how-redgate-helped-define-our-process/

Page 89: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

DLMConsultants.com/ci

Page 90: Getting CI right for SQL Server
Page 91: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Questions?

Links: DLMConsultants.com/ciContact me: [email protected]

Page 92: Getting CI right for SQL Server

@_AlexYates_#SQLLeeds

Image sourcesAuthor 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