Top Banner
@_AlexYate s_ #ManSSUG Getting CI right for SQL Server Alex Yates
83

Getting CI right for SQL Server

Apr 13, 2017

Download

Technology

Alex Yates
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Getting CI right for SQL Server

Alex Yates

Page 2: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

DLM Consultant

workingwithdevs.com

[email protected]

Alex Yates

@_AlexYates_

Page 3: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

@_AlexYates_ | #ManSSUG

Page 4: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

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 5: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

What is CI?

Page 6: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

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 7: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

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

Page 8: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Farm Credit Services of America (FCSA)

• Growing test suite

• Delivery faster and more reliable

• Standardised source control process

• Automated builds/deploys from source control

Page 9: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

The deployment pipeline

Page 10: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

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 11: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

The deployment pipeline

Page 12: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 13: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 14: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Version Control

Page 15: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Version control - LMGTFY

Page 16: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 17: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 18: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

There’s more than one way to skin a cat

Page 19: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

There’s more than one way to skin automatea cat

Page 20: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

V1 V2

Page 21: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

V1 V2

Migrations-based solutions

Page 22: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

V1 V2

State-based solutions

Page 23: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Page 24: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

“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 25: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

“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 26: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

“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 27: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

“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 28: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Migrations vs state

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

Page 29: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Migrations vs state

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

Page 30: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Migrations vs state

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

Page 31: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Migrations vs state

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

Page 32: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Migrations vs state

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

Page 33: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Migrations vs state

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

Page 34: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Migrations vs state

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

Page 35: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

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 36: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

DLMConsultants.com/model-vs-mig

Page 37: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Demo

Page 38: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 39: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 40: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Continuous Integration

Page 41: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Build servers

Page 42: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

VCS Build Test Sync

Upgrade scriptDatabase package

Test results

The automated build process

Page 43: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Builds/Tests are run on CI agents

Builds/Tests are managed on

CI server

CI server

How do build servers work?

Page 44: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Demo

Page 45: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 46: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 47: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Unit testing

Page 48: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Unit testing

www.tsqlt.org

Page 49: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Unit testing

www.tsqlt.org

Page 50: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Unit testing

www.tsqlt.org

Page 51: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

www.tsqlt.org

Unit testing

Page 52: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Unit testing

Page 53: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Unit testing

Page 54: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

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

Page 55: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Demo

Page 56: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 57: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 58: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Drift

Page 59: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Page 60: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

“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 61: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

“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 62: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

The bad stuff:

• Accidental roll-backs (state)

• Failed deployments (migrations)

• Environment inconsistency (migrations)

Page 63: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

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 64: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

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 65: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Demo

Page 66: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 67: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 68: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

• Teamwork above tools/process• Don’t do *all the things* at once - start with VCS and drift• Don’t forget tests• Decouple database from other systems• Learn CI on an easy database/project• Use the right process/tool for your database and team

• Ask me for help!

General advice

Page 69: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

AgendaVersion control

Model vs migrationsAutomated builds

Unit testingDrift

General advice

Page 70: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

• 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 71: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

• 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 72: Getting CI right for SQL Server
Page 73: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Siloed sparrows suck at DLM

Page 74: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Heated hippos are closed minded

Page 75: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

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 76: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Use appropriate tools

Page 77: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Only hire developers who write tests

Page 78: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

Hunt his smug face - make pain on it

Page 79: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

This stuff makes a big difference

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

Page 80: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

DLMConsultants.com/ci

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

@_AlexYates_#ManSSUG

Questions?

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

Page 83: Getting CI right for SQL Server

@_AlexYates_#ManSSUG

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