SlideShare una empresa de Scribd logo
1 de 45
SQL Server
Development Best
Practices
Source Control, Testing, and
Continuous Integration
Ike Ellis, MVP
The Monastery
Please silence
cell phones
Explore Everything PASS Has to Offer
Free SQL Server and BI Web Events Free 1-day Training Events Regional Event
Local User Groups Around
the World
Free Online Technical Training
This is Community Business Analytics Training
Session Recordings PASS Newsletter
Session Evaluations
ways to access
Go to
passsummit.com/evals
Download the GuideBook App
and search: PASS Summit 2014
Follow the QR code link displayed
on session signage throughout the
conference venue and in the
program guide
Submit by 11:59 PM EST
Friday Nov. 7 to
WIN prizes
Your feedback is
important and valuable.
Evaluation Deadline:
11:59 PM EST, Sunday Nov. 16
Agenda
• Source Control
• Testing
• SQLCop
• Continuous Integration
• Continuous Deployment
• Tooling
No Developer Left Behind
Time
Main Trunk
New Dev Working
When Integration Time Strikes
Longer Time = More Errors
More errors to solve, means more time to solve errors
Dev continues, prolonging error correcting time
Integration might never happen
Time
Main Trunk
New Dev Working
Shorten the Time
Less or no problems to solve
Deployment can always happen
Code on every workstation is in a build
ready condition
Main Trunk
New Dev Working
• Complicated deployment is always messed up
• Same simple deployment, but hundreds of times (lots of
customers – multitenancy)
Other problems
“Great software developers are 127 times more effective
than average, but only require 50% higher salary, making
them the best bargain in business.”
Martin Fowler
• Change tracking
• Code storage
• Permissions
• History
What is source control?
• Check-in
• Check-out
• Merge
• Branch
• Undo
• Lock
SC: Process
• Management visibility
• Productive developers
• Allows insight into all work done
• Compliance and auditing
• Scalable team
• Code delivery
• History tracking
• Rollback capable
• Safety net
• Allows for danger/manages risk
Source Control: Benefits
Source Control: Products
• Version control is easy with files
• Much harder with a managed database file
SC: Problems with the Database
• Everything’s a file (any product)
• Migrations/file versions/update scripts
• TFS
• Notion of offline, disconnected dev
• RedGate
• ApexSQL
SC: Options
Check in Lookup Table/Data
http://blogs.msdn.com/b/ssdt/archive/2012/02/02/includin
g-data-in-an-sql-server-database-project.aspx
Building CI with TFS
http://blogs.msdn.com/b/ssdt/archive/2014/07/24/sql-
server-database-projects-and-team-foundation-build.aspx
References
Source Control
Demo
• Write code all day…never write a test
• Something breaks
• Cheapest place to find the bug?
Unit Testing: What happens without it
Write a bug QA Testing Deliver
Bug Correction Time
0.85
Find A Bug Fix A Bug
• Automated and self-checked procedure used to validate
that a particular module of source code works correctly
• Write tests for Triggers, Stored Procedures, Functions
Unit Test: What is it?
Arrange
Act
Assert
Unit Test: Process
• Documents code functionality
• Better than commenting code
• Allows refactoring
• Red Green Refactor Repeat
Unit Testing: Benefits
Unit Testing: Main Benefit
Tests get checked in and run regularly
Prevents same bug from happening again
Unit Testing & Source Control
• Unit testing framework for MS SQL Server
• Compatible with SQL Server 2005 and above
• Tests are run inside transaction
• Grouped together in a schema
• Output to text or XML
• Fake tables and views
• Spy on stored procedures
tSQLt
• Supports sproces, functions, and table triggers
• Needs a test project and a SQL test class added to that
project
• Test Explorer
TFS Unit Testing
Tracks SQL Best Practices
Free
Sprocs come with SQLTest
SQLCop
Unit Testing
Demo
• Long names = OK
• Test small chunks
• Covering is overrated
• Tests take no arguments
• Not all sprocs are testable, but if testing is what you do,
you’ll write better sprocs
• Test against a different database than development
• Insolate yourself from development database changes that rapidly change
Testing Best Practices
CI: The Integration/Deployment Process
We do it when we feel like it
We do it daily
We do it on a schedule
We do it at every check-in to source control
CI: Benefits
• Avoids the “Works on My PC” syndrome
• All developers can get their work deployed and not be left behind
• Tests can be run constantly, and breaking tests can generate
emails, thus inspiring code confidence
• Higher quality in code
• Automatically build documentation, remove unneeded files,
include dependencies
• Increased visibility of project
• Deployment can be separate from developers
• Easier to deploy dev environment to new developers
CI: Working with Legacy Code
First thing we do is deploy
Can we deploy
Is source control accurate?
CI Fundamentals
Build Steps = Automatically Build Stuff = Scripts
Build Triggers = What makes us build?
Build Agents = What can we do in the CI process?
Build Notifications = Who gets told what and when?
Build Correction = What went wrong and who will solve it?
CI Products
CruiseControl
Hudson
JetBrains = TeamCity
MSBuild/TFS
RedGate CI for databases
CI Process (An Example)
Step 1: Check in from source control
Step 2: Build Trigger begins a build, CI takes over
Step 3: CI builds the solution
Step 4: CI runs all the tests
Step 5: CI deploys package to a UAT server
Step 6: CI notifies everyone a new build is ready to test
Best Practices – Don’t Break the Build
Check-in several times
a day
Merge changes at
every check-in
If you broke the build,
tell everyone, so they
can stop getting latest
from source control
Don’t check-in until
the build is fixed
Notify everyone once
the build is fixed
Continuous Integration
Demo
• Great for velocity
• Used when it’s a single system with many complicated
parts
• Load balancers
• file servers
• databases
• web services
• Or a simple system, but replicated many times, like multi-
tenancy
• Or both
Continuous Deployment
Continuous Deployment
Demo
Code &
Write Tests
Check-in
Run Tests
& Integrate
Create
Build
Deploy to
UAT
Deploy to
Production
Generic Tools
Database Tools
Visual Studio
Subversion
GIT
TFS
TFS(Test & Buid)
TeamCity
Jenkins
CruiseControl Octopus Deploy
SSDT
SSMS
RedGate
ApexSQL
SSDT
tSQLt
RedGate Test
SSDT
SSDT
RedGate
RedGate
• Write tests to avoid errors with missing objects, schema changes,
bad logic, and bad migrations
• Use source control and versioning to create a good migration
• Use CI to create a build that is repeatable and roll-backable
• Every developer should have their own database
• Use CD to control complicated build systems with moving parts, or
repeatable simple build systems, like multi-tenancy
Do what you know you’re supposed
to be doing
Conclusion and Best Practices
Ike Ellis, MVP
• http://www.ikeellis.com
• The Monastery
• SQL Pass Book Readers
• San Diego Tech Immersion Group
• @ike_ellis
• 619.922.9801
• Email address is just my first name @the-monastery.com

Más contenido relacionado

Más de Ike Ellis

Data modeling trends for Analytics
Data modeling trends for AnalyticsData modeling trends for Analytics
Data modeling trends for AnalyticsIke Ellis
 
Relational data modeling trends for transactional applications
Relational data modeling trends for transactional applicationsRelational data modeling trends for transactional applications
Relational data modeling trends for transactional applicationsIke Ellis
 
Power bi premium
Power bi premiumPower bi premium
Power bi premiumIke Ellis
 
Move a successful onpremise oltp application to the cloud
Move a successful onpremise oltp application to the cloudMove a successful onpremise oltp application to the cloud
Move a successful onpremise oltp application to the cloudIke Ellis
 
Azure Databricks is Easier Than You Think
Azure Databricks is Easier Than You ThinkAzure Databricks is Easier Than You Think
Azure Databricks is Easier Than You ThinkIke Ellis
 
Pass 2018 introduction to dax
Pass 2018 introduction to daxPass 2018 introduction to dax
Pass 2018 introduction to daxIke Ellis
 
Pass the Power BI Exam
Pass the Power BI ExamPass the Power BI Exam
Pass the Power BI ExamIke Ellis
 
Slides for PUG 2018 - DAX CALCULATE
Slides for PUG 2018 - DAX CALCULATESlides for PUG 2018 - DAX CALCULATE
Slides for PUG 2018 - DAX CALCULATEIke Ellis
 
Introduction to DAX
Introduction to DAXIntroduction to DAX
Introduction to DAXIke Ellis
 
60 reporting tips in 60 minutes - SQLBits 2018
60 reporting tips in 60 minutes - SQLBits 201860 reporting tips in 60 minutes - SQLBits 2018
60 reporting tips in 60 minutes - SQLBits 2018Ike Ellis
 
14 Habits of Great SQL Developers
14 Habits of Great SQL Developers14 Habits of Great SQL Developers
14 Habits of Great SQL DevelopersIke Ellis
 
14 Habits of Great SQL Developers
14 Habits of Great SQL Developers14 Habits of Great SQL Developers
14 Habits of Great SQL DevelopersIke Ellis
 
Dive Into Azure Data Lake - PASS 2017
Dive Into Azure Data Lake - PASS 2017Dive Into Azure Data Lake - PASS 2017
Dive Into Azure Data Lake - PASS 2017Ike Ellis
 
A lap around microsofts business intelligence platform
A lap around microsofts business intelligence platformA lap around microsofts business intelligence platform
A lap around microsofts business intelligence platformIke Ellis
 
Survey of the Microsoft Azure Data Landscape
Survey of the Microsoft Azure Data LandscapeSurvey of the Microsoft Azure Data Landscape
Survey of the Microsoft Azure Data LandscapeIke Ellis
 
11 Goals of High Functioning SQL Developers
11 Goals of High Functioning SQL Developers11 Goals of High Functioning SQL Developers
11 Goals of High Functioning SQL DevelopersIke Ellis
 
SQL PASS BAC - 60 reporting tips in 60 minutes
SQL PASS BAC - 60 reporting tips in 60 minutesSQL PASS BAC - 60 reporting tips in 60 minutes
SQL PASS BAC - 60 reporting tips in 60 minutesIke Ellis
 
Introduction to Azure DocumentDB
Introduction to Azure DocumentDBIntroduction to Azure DocumentDB
Introduction to Azure DocumentDBIke Ellis
 
Azure DocumentDB 101
Azure DocumentDB 101Azure DocumentDB 101
Azure DocumentDB 101Ike Ellis
 
Tips & Tricks SQL in the City Seattle 2014
Tips & Tricks SQL in the City Seattle 2014Tips & Tricks SQL in the City Seattle 2014
Tips & Tricks SQL in the City Seattle 2014Ike Ellis
 

Más de Ike Ellis (20)

Data modeling trends for Analytics
Data modeling trends for AnalyticsData modeling trends for Analytics
Data modeling trends for Analytics
 
Relational data modeling trends for transactional applications
Relational data modeling trends for transactional applicationsRelational data modeling trends for transactional applications
Relational data modeling trends for transactional applications
 
Power bi premium
Power bi premiumPower bi premium
Power bi premium
 
Move a successful onpremise oltp application to the cloud
Move a successful onpremise oltp application to the cloudMove a successful onpremise oltp application to the cloud
Move a successful onpremise oltp application to the cloud
 
Azure Databricks is Easier Than You Think
Azure Databricks is Easier Than You ThinkAzure Databricks is Easier Than You Think
Azure Databricks is Easier Than You Think
 
Pass 2018 introduction to dax
Pass 2018 introduction to daxPass 2018 introduction to dax
Pass 2018 introduction to dax
 
Pass the Power BI Exam
Pass the Power BI ExamPass the Power BI Exam
Pass the Power BI Exam
 
Slides for PUG 2018 - DAX CALCULATE
Slides for PUG 2018 - DAX CALCULATESlides for PUG 2018 - DAX CALCULATE
Slides for PUG 2018 - DAX CALCULATE
 
Introduction to DAX
Introduction to DAXIntroduction to DAX
Introduction to DAX
 
60 reporting tips in 60 minutes - SQLBits 2018
60 reporting tips in 60 minutes - SQLBits 201860 reporting tips in 60 minutes - SQLBits 2018
60 reporting tips in 60 minutes - SQLBits 2018
 
14 Habits of Great SQL Developers
14 Habits of Great SQL Developers14 Habits of Great SQL Developers
14 Habits of Great SQL Developers
 
14 Habits of Great SQL Developers
14 Habits of Great SQL Developers14 Habits of Great SQL Developers
14 Habits of Great SQL Developers
 
Dive Into Azure Data Lake - PASS 2017
Dive Into Azure Data Lake - PASS 2017Dive Into Azure Data Lake - PASS 2017
Dive Into Azure Data Lake - PASS 2017
 
A lap around microsofts business intelligence platform
A lap around microsofts business intelligence platformA lap around microsofts business intelligence platform
A lap around microsofts business intelligence platform
 
Survey of the Microsoft Azure Data Landscape
Survey of the Microsoft Azure Data LandscapeSurvey of the Microsoft Azure Data Landscape
Survey of the Microsoft Azure Data Landscape
 
11 Goals of High Functioning SQL Developers
11 Goals of High Functioning SQL Developers11 Goals of High Functioning SQL Developers
11 Goals of High Functioning SQL Developers
 
SQL PASS BAC - 60 reporting tips in 60 minutes
SQL PASS BAC - 60 reporting tips in 60 minutesSQL PASS BAC - 60 reporting tips in 60 minutes
SQL PASS BAC - 60 reporting tips in 60 minutes
 
Introduction to Azure DocumentDB
Introduction to Azure DocumentDBIntroduction to Azure DocumentDB
Introduction to Azure DocumentDB
 
Azure DocumentDB 101
Azure DocumentDB 101Azure DocumentDB 101
Azure DocumentDB 101
 
Tips & Tricks SQL in the City Seattle 2014
Tips & Tricks SQL in the City Seattle 2014Tips & Tricks SQL in the City Seattle 2014
Tips & Tricks SQL in the City Seattle 2014
 

Último

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

Último (20)

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

ALM Best Practices with a SQL Server Database

  • 1. SQL Server Development Best Practices Source Control, Testing, and Continuous Integration Ike Ellis, MVP The Monastery
  • 3. Explore Everything PASS Has to Offer Free SQL Server and BI Web Events Free 1-day Training Events Regional Event Local User Groups Around the World Free Online Technical Training This is Community Business Analytics Training Session Recordings PASS Newsletter
  • 4. Session Evaluations ways to access Go to passsummit.com/evals Download the GuideBook App and search: PASS Summit 2014 Follow the QR code link displayed on session signage throughout the conference venue and in the program guide Submit by 11:59 PM EST Friday Nov. 7 to WIN prizes Your feedback is important and valuable. Evaluation Deadline: 11:59 PM EST, Sunday Nov. 16
  • 5. Agenda • Source Control • Testing • SQLCop • Continuous Integration • Continuous Deployment • Tooling
  • 6.
  • 7. No Developer Left Behind Time Main Trunk New Dev Working
  • 8. When Integration Time Strikes Longer Time = More Errors More errors to solve, means more time to solve errors Dev continues, prolonging error correcting time Integration might never happen Time Main Trunk New Dev Working
  • 9. Shorten the Time Less or no problems to solve Deployment can always happen Code on every workstation is in a build ready condition Main Trunk New Dev Working
  • 10. • Complicated deployment is always messed up • Same simple deployment, but hundreds of times (lots of customers – multitenancy) Other problems
  • 11. “Great software developers are 127 times more effective than average, but only require 50% higher salary, making them the best bargain in business.” Martin Fowler
  • 12. • Change tracking • Code storage • Permissions • History What is source control?
  • 13. • Check-in • Check-out • Merge • Branch • Undo • Lock SC: Process
  • 14. • Management visibility • Productive developers • Allows insight into all work done • Compliance and auditing • Scalable team • Code delivery • History tracking • Rollback capable • Safety net • Allows for danger/manages risk Source Control: Benefits
  • 16. • Version control is easy with files • Much harder with a managed database file SC: Problems with the Database
  • 17. • Everything’s a file (any product) • Migrations/file versions/update scripts • TFS • Notion of offline, disconnected dev • RedGate • ApexSQL SC: Options
  • 18. Check in Lookup Table/Data http://blogs.msdn.com/b/ssdt/archive/2012/02/02/includin g-data-in-an-sql-server-database-project.aspx Building CI with TFS http://blogs.msdn.com/b/ssdt/archive/2014/07/24/sql- server-database-projects-and-team-foundation-build.aspx References
  • 20. • Write code all day…never write a test • Something breaks • Cheapest place to find the bug? Unit Testing: What happens without it Write a bug QA Testing Deliver
  • 21. Bug Correction Time 0.85 Find A Bug Fix A Bug
  • 22. • Automated and self-checked procedure used to validate that a particular module of source code works correctly • Write tests for Triggers, Stored Procedures, Functions Unit Test: What is it?
  • 24. • Documents code functionality • Better than commenting code • Allows refactoring • Red Green Refactor Repeat Unit Testing: Benefits
  • 26. Tests get checked in and run regularly Prevents same bug from happening again Unit Testing & Source Control
  • 27. • Unit testing framework for MS SQL Server • Compatible with SQL Server 2005 and above • Tests are run inside transaction • Grouped together in a schema • Output to text or XML • Fake tables and views • Spy on stored procedures tSQLt
  • 28. • Supports sproces, functions, and table triggers • Needs a test project and a SQL test class added to that project • Test Explorer TFS Unit Testing
  • 29. Tracks SQL Best Practices Free Sprocs come with SQLTest SQLCop
  • 31. • Long names = OK • Test small chunks • Covering is overrated • Tests take no arguments • Not all sprocs are testable, but if testing is what you do, you’ll write better sprocs • Test against a different database than development • Insolate yourself from development database changes that rapidly change Testing Best Practices
  • 32. CI: The Integration/Deployment Process We do it when we feel like it We do it daily We do it on a schedule We do it at every check-in to source control
  • 33. CI: Benefits • Avoids the “Works on My PC” syndrome • All developers can get their work deployed and not be left behind • Tests can be run constantly, and breaking tests can generate emails, thus inspiring code confidence • Higher quality in code • Automatically build documentation, remove unneeded files, include dependencies • Increased visibility of project • Deployment can be separate from developers • Easier to deploy dev environment to new developers
  • 34. CI: Working with Legacy Code First thing we do is deploy Can we deploy Is source control accurate?
  • 35. CI Fundamentals Build Steps = Automatically Build Stuff = Scripts Build Triggers = What makes us build? Build Agents = What can we do in the CI process? Build Notifications = Who gets told what and when? Build Correction = What went wrong and who will solve it?
  • 36. CI Products CruiseControl Hudson JetBrains = TeamCity MSBuild/TFS RedGate CI for databases
  • 37. CI Process (An Example) Step 1: Check in from source control Step 2: Build Trigger begins a build, CI takes over Step 3: CI builds the solution Step 4: CI runs all the tests Step 5: CI deploys package to a UAT server Step 6: CI notifies everyone a new build is ready to test
  • 38. Best Practices – Don’t Break the Build Check-in several times a day Merge changes at every check-in If you broke the build, tell everyone, so they can stop getting latest from source control Don’t check-in until the build is fixed Notify everyone once the build is fixed
  • 40. • Great for velocity • Used when it’s a single system with many complicated parts • Load balancers • file servers • databases • web services • Or a simple system, but replicated many times, like multi- tenancy • Or both Continuous Deployment
  • 42.
  • 43. Code & Write Tests Check-in Run Tests & Integrate Create Build Deploy to UAT Deploy to Production Generic Tools Database Tools Visual Studio Subversion GIT TFS TFS(Test & Buid) TeamCity Jenkins CruiseControl Octopus Deploy SSDT SSMS RedGate ApexSQL SSDT tSQLt RedGate Test SSDT SSDT RedGate RedGate
  • 44. • Write tests to avoid errors with missing objects, schema changes, bad logic, and bad migrations • Use source control and versioning to create a good migration • Use CI to create a build that is repeatable and roll-backable • Every developer should have their own database • Use CD to control complicated build systems with moving parts, or repeatable simple build systems, like multi-tenancy Do what you know you’re supposed to be doing Conclusion and Best Practices
  • 45. Ike Ellis, MVP • http://www.ikeellis.com • The Monastery • SQL Pass Book Readers • San Diego Tech Immersion Group • @ike_ellis • 619.922.9801 • Email address is just my first name @the-monastery.com