Post on 27-Nov-2014
description
Get Your Database Under Control
Steve JonesRed Gate Software
Goals
• Understand the value of version/source control for databases
• Learn the tools, standards, patterns and best practices needed to manage a database from source control
• Identify the necessary flow within a team needed to develop a database with source control
Get in touch
www.voiceofthedba.comsjones@sqlservercentral.com
@way0utwest
Steve Jones
How many of you use version control for your application code?
C#, ASP.NET, Javascript, VB.NET, etc.
database
How many of you use version control for your application code?
Developers who refuse to use source/version control should be
fired, simple as that.
Isn’t this too much trouble for my crappy experimental
program?
Use source control because neither you nor your
developers are perfect.
There are no excuses where you should not use it.
If it’s not in source control, it doesn’t exist.
“…your database should always be under source
control right next to your application code.”
Reducing Risk
You’re using version control
You’re using version control
Use Something
Demo
Getting started with databases in VCS
Additional Reasons for Source Control
• Backup & Restore• Undo• Audit changes• Sandbox• Branching/Merging
Rules for Database Development
Never use a shared database for development.
Always Have a Single, Authoritative Source
For Your Schema.
Always Version Your Database.
The Ideal
• Each developer has a dedicated environment with a copy of the schema and minimal data.
• A shared integration environment where all developers’ changes are merged, available for developer testing.
Patterns and Practices• Get all your code
– Object DDL– Assembly code– Security grants and revokes– Database configuration settings– Jobs for your application– Lookup data
Patterns and Practices
• Commit Early, Commit Often• Use meaningful comments. Why, not what.• Check for changes often• Use common names and code patterns• Use tools• Branch Rarely
Teamwork
Teamwork
• Communicationo Team members need to be aware of
(easily) what others are doing.
• Coordinationo Teams need to work in a way that
complements each other.
Teamwork
• CommunicationoReview each other’s code as you
refactoro Share knowledge
o CoordinationoDecide on common code styles and
namesoAnd …
Teach
Demo
The flow within teams
Reasons to Branch
• Release• Hot Fixes• New Development• Integration• Feature set
Reasons to Branch
• Release• Hot Fixes• New Development• Integration• Feature set
Demo
Branching
Best Practices
• Use version control for all code (including tests)
• Commit early, commit often• Use tools
o If it’s hard, people don’t do it• Train people• Build often
Automation
Automation
Deploymentpackage
deployment package1
2
3
Development
FAIL
Goals
• Understand the value of version/source control for databases
• Learn the tools, standards, patterns and best practices needed to manage a database from source control
• Identify the necessary flow within a team needed to develop a database with source control
Want to try the tools you’ve just seen? Come to our Hands-on Labs
www.voiceofthedba.com
@way0utwest
sjones@sqlservercentral.com
Thanks for coming
References
• http://stackoverflow.com/questions/115369/do-you-use-source-control-for-your-database-items
• http://www.codinghorror.com/blog/archives/001050.html• http://www.codinghorror.com/blog/2008/02/get-your-database-unde
r-version-control.html
• http://www.ssw.com.au/ssw/Standards/Rules/RulesToBetterSQLServerDatabases.aspx
• http://odetocode.com/blogs/scott/archive/2008/01/30/three-rules-for-database-work.aspx
• Check in early, check in often - http://www.codinghorror.com/blog/2008/08/check-in-early-check-in-often.html
• http://betterexplained.com/articles/a-visual-guide-to-version-control/
Credits
• https://www.flickr.com/photos/doug88888/8349818088/in/photostream/
• https://www.flickr.com/photos/8525214@N06/5132974421