Agile Database Development - SDC2012
-
Upload
jose-luis-soria -
Category
Technology
-
view
3.747 -
download
4
description
Transcript of Agile Database Development - SDC2012
![Page 1: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/1.jpg)
Agile Database development
(with Visual Studio)
Jose Luis Soria
Göteborg, April 2012
![Page 2: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/2.jpg)
Jose Luis Soria
• ALM Team Lead at
Plain Concepts
• Professional Scrum
Trainer at scrum.org
http://geeks.ms/blogs/jlsoria
@jlsoriat
![Page 3: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/3.jpg)
Agenda
• Database development
• Agile development
• Agile database development
• Practices and tools
![Page 4: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/4.jpg)
Database development
![Page 5: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/5.jpg)
How databases work
• Databases are different from application code
– Application code is not changed while
running (even in dynamic languages, changes are not
persisted)
– Databases are changed while running
• Changes in data or database objects, made
while the database is online, have to be taken
into account while developing
![Page 6: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/6.jpg)
![Page 7: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/7.jpg)
Databases are changed while running
Take running database changes intoaccount while developing.
Have a proper policy for changes in place
![Page 8: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/8.jpg)
Databases across environments
• We have to deal with several environments while developing
• Each environment has its own database
• These databases are used for different things
• These databases are in different states and versions, and contain different data
![Page 9: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/9.jpg)
Databases are differentacross environments
Be prepared to change different thingsin different databases
![Page 10: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/10.jpg)
Applying changes to databases
• Most times, any particular change can only be made one time. Once the change has been made, it is not possible to make it again
• Changes are difficult to be undone
![Page 11: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/11.jpg)
Changes to databases are lastingand hard to be undone
Have a proper policy for changes in place.Have a proper policy for undoing
changes in place.
![Page 12: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/12.jpg)
Agile development
![Page 13: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/13.jpg)
Agile?
![Page 14: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/14.jpg)
Twelve principles of AgileOur highest priority is to satisfy the customer through early and continuous delivery of valuable software.
Working software is the primary measure of progress.
Welcome changing requirements, even late in development. Agile processes harness change for the customer's competitive advantage.
Agile processes promote sustainable development. The sponsors, developers, and users should be able to maintain a constant pace indefinitely.
Deliver working software frequently, from a couple of weeks to a couple of months, with a preference to the shorter timescale.
Continuous attention to technical excellence and good design enhances agility.
Business people and developers must work together daily throughout the project.
Simplicity--the art of maximizing the amount of work not done--is essential.
Build projects around motivated individuals. Give them the environment and support they need, and trust them to get the job done.
The best architectures, requirements, and designs emerge from self-organizing teams.
The most efficient and effective method of conveying information to and within a development team is face-to-face conversation.
At regular intervals, the team reflects on how to become more effective, then tunes and adjusts its behavior accordingly.
![Page 15: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/15.jpg)
Twelve principles of AgileOur highest priority is to satisfy the customer through early and continuous delivery of valuable software.
Working software is the primary measure of progress.
Welcome changing requirements, even late in development. Agile processes harness change for the customer's competitive advantage.
Agile processes promote sustainable development. The sponsors, developers, and users should be able to maintain a constant pace indefinitely.
Deliver working software frequently, from a couple of weeks to a couple of months, with a preference to the shorter timescale.
Continuous attention to technical excellence and good design enhances agility.
Business people and developers must work together daily throughout the project.
Simplicity--the art of maximizing the amount of work not done--is essential.
Build projects around motivated individuals. Give them the environment and support they need, and trust them to get the job done.
The best architectures, requirements, and designs emerge from self-organizing teams.
The most efficient and effective method of conveying information to and within a development team is face-to-face conversation.
At regular intervals, the team reflects on how to become more effective, then tunes and adjusts its behavior accordingly.
![Page 16: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/16.jpg)
Agile database development
Early and continuous delivery of
valuable software.
Working software is the primary
measure of progress.
Welcome changing requirements. Sustainable development, constant
pace.
Deliver working software
frequently.
Continuous attention to technical
excellence and good design.
Business people and developers
must work together.
Simplicity.
Build projects around motivated
individuals. Give them the
environment and support they
need.
The best architectures,
requirements, and designs emerge.
![Page 17: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/17.jpg)
What does it mean?
![Page 18: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/18.jpg)
Early and continuous delivery ofvaluable software
Ability to deliver in a simple and quickway
![Page 19: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/19.jpg)
Welcome changing requirements
Ability to introduce changesat any moment
![Page 20: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/20.jpg)
Deliver working software frequently
Ability to deliver in a simple and quickway
![Page 21: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/21.jpg)
Business people and developersmust work together
Development depends on business
![Page 22: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/22.jpg)
Build projects around motivated individuals.Give them the environment they need
Proper environment and tools
![Page 23: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/23.jpg)
Working softwareis the primary measure of progress
Development depends on business.Keep always
a functional version of the software
![Page 24: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/24.jpg)
Sustainable development.Constant pace
Ability to introduce changesat any moment
![Page 25: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/25.jpg)
Continuous attention to technicalexcellence and good design
Best practices: CI, refactoring, TDD…
![Page 26: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/26.jpg)
Simplicity
Reuse.Work in small chunks
![Page 27: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/27.jpg)
The best architectures, requirementsand designs emerge
Ability to introduce changesat any moment
![Page 28: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/28.jpg)
Agile database development
![Page 29: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/29.jpg)
Agile database development
• Be able to deliver database changes in a simple and quick way
• Be able to introduce database changes at any moment• Make database development dependent on business• Set up a proper environment and tools• Keep always a functional version of the database• Use best practices: CI, refactoring, TDD…• Reuse• Work in small chunks• Take running database changes into account while
developing• Have a proper policy for changes in place• Have a proper policy for undoing changes in place• Be prepared to change different things in different databases
![Page 30: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/30.jpg)
How to do it?: practices & tools
![Page 31: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/31.jpg)
Practices and tools
• Are going to help us to do database development properly
• Tools and demos for this session deal with relational databases (SQL Server). But principles are the same for other scenarios:– NoSQL (MongoDB, Azure Storage…)
– ORMs (Entity Framework, NHibernate…)
• Most things will also work with VS 11 and SQL Server Data Tools
![Page 32: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/32.jpg)
Version control
• Treat database code like any other source code
– Enable several people to work on the same code base
– Make modifications available to the rest of the team in a controlled way
– Make it possible to set up Continuous Integration
– Use versioning features: compare, restore old version, combine…
• Use the same code, schema or approach to migrate any database in your environment
![Page 33: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/33.jpg)
DemoVersion control for databases
![Page 34: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/34.jpg)
Coding aids
• Visual Studio provides several aids for working with database code
– Intellisense
– Tracking and resolving dependencies
– Static analysis
– Refactoring
![Page 35: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/35.jpg)
DemoCoding aids
![Page 36: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/36.jpg)
Isolated development
environment
• Have each developer work in his own environment, which includes the database
– Self-contained
– Resembling production environment
– Automated (deployment, testing, etc.)
![Page 37: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/37.jpg)
DemoIsolated development
environment
![Page 38: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/38.jpg)
Unit tests
• Sometimes, database code can contain logic
• Database code can benefit from automated unit testing the same way as application code– Find problems early
– Facilitate change
– Simplify integration
– Self-document
– Drive the design
![Page 39: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/39.jpg)
DemoDatabase unit testing
![Page 40: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/40.jpg)
Continuous Integration
• Early warning of conflicting changes
• Immediate unit testing of all changes
• Constant availability of a "current" build for testing, demo, or release purposes
• Immediate feedback
• Modular, less complex code
• Quality code
![Page 41: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/41.jpg)
Continuous Integration
principles
• Maintain a code repository
• Automate the build
• Make the build self-testing
• Everyone commits to the baseline every day
• Every commit (to baseline) should be built
• Keep the build fast
• Test in a clone of the production environment
• Make it easy to get the latest deliverables
• Everyone can see the results of the latest build
• Automate deployment
![Page 42: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/42.jpg)
Continuous Integration
principles
• Maintain a code repository
• Automate the build
• Make the build self-testing
• Everyone commits to the baseline every day
• Every commit (to baseline) should be built
• Keep the build fast
• Test in a clone of the production environment
• Make it easy to get the latest deliverables
• Everyone can see the results of the latest build
• Automate deployment
![Page 43: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/43.jpg)
DemoDatabase continuous
integration
![Page 44: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/44.jpg)
Requirements drive changes
• Make changes in small chunks
• Changes are originated by requirements
• Make different changes for different requirements
![Page 45: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/45.jpg)
Continuous deployment to any
environment
• Automating database migrations to any environment helps us:
– Easily roll forward or back
– Minimize disruption for changes
– Maximize reliability of deployment process
– Work incrementally (including DBAs)
![Page 46: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/46.jpg)
Continuous deployment process
• Obtain the correct version of the
database
• Prepare the environment
• Initialize database and instance
• Initialize schema
• Initialize user credentials
• Populate database with reference data
• Have a rollback mechanism in place
![Page 47: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/47.jpg)
DemoContinuous deployment
![Page 48: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/48.jpg)
Database sync vs. delta scripts
• Syncing databases can lead to uncontrolled changes across environments
• It’s better to make changes the same way for all the environments
• We can use numerated delta scripts and tools like DBDeploy
![Page 49: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/49.jpg)
Database sync vs. delta scripts
• Delta scripts– Great for greenfield development and Continuous
Integration
• Database sync– For legacy databases
– For non-agile, non-CI projects
– For changing data
– When you don’t have database under version control
• Other options– ORMs usually have their own mechanism to deal with
database changes. For example, migrations in Entity Framework
![Page 50: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/50.jpg)
Dealing with data
• Reference data can be scripted
• Changes (delta scripts) should deal with existing data
• There are several ways to obtain data for testing– Using the application API
– Using backups
– Using data comparison tools
– Using data generation tools
![Page 51: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/51.jpg)
Have we covered everything?
• Be able to deliver database changes in a simple and quick way
• Be able to introduce database changes at any moment• Make database development dependent on business• Set up a proper environment and tools• Keep always a functional version of the database• Use best practices: CI, refactoring, TDD…• Reuse• Work in small chunks• Take running database changes into account while
developing• Have a proper policy for changes in place• Have a proper policy for undoing changes in place• Be prepared to change different things in different databases
![Page 52: Agile Database Development - SDC2012](https://reader035.fdocuments.in/reader035/viewer/2022081403/5578e3cad8b42a5c5c8b4853/html5/thumbnails/52.jpg)
Any questions?
• Visual Studio Database tools http://bit.ly/dyN3wv
• VSDBCMD http://bit.ly/vB6G1
• Database changes done right http://bit.ly/wTOY01
• Continuous delivery http://continuousdelivery.com/
@jlsoriat