Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Database automated build and test - SQL In The City Cambridge

1,464 views

Published on

Automated Database Build and Test. Presentation from David Atkinson at SQL In The City Cambridge.

Published in: Technology
  • D0WNL0AD FULL ▶ ▶ ▶ ▶ http://1lite.top/SxF8U ◀ ◀ ◀ ◀
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Database automated build and test - SQL In The City Cambridge

  1. 1. #sqlinthecity Automated Build and Test (or continuous integration) (for your database) David Atkinson Product Manager, Red Gate David.Atkinson@red-gate.com
  2. 2. #sqlinthecity What will we cover today? Database build automation: What, Why, How Practical Demo Questions encouraged!
  3. 3. #sqlinthecity Show of hands: How agile is your database development? 1. Database objects/scripts aren’t in version control 2. Database objects/scripts are in version control 3. An automated build system exists to build and test the database 4. An automated release system is used to promote your database to your environments
  4. 4. #sqlinthecity How agile is your database development? 1. Database objects/scripts aren’t in version control 2. Database objects/scripts are in version control 3. An automated build system exists to build and test the database 4. An automated release system is used to promote your database to your environments
  5. 5. #sqlinthecity What is continuous integration? “Continuous Integration is a practice designed to ensure that your software is always working, and that you get comprehensive feedback in a few minutes as to whether any given change to your system has broken it.” Jez Humble, ThoughtWorks, author of “Continuous Delivery”
  6. 6. database #sqlinthecity What is continuous integration? ^ “Database Continuous Integration is a practice designed to ensure that your database software is always working, and that you get comprehensive feedback in a few minutes as to whether any given change to your system has broken it.”
  7. 7. #sqlinthecity Database Build Automation
  8. 8. #sqlinthecity What is build? • For application code = compile • For database code = database creation script – But only for a new installation! • Upgrade scripts required for existing installations – Need to preserve the state of the data
  9. 9. #sqlinthecity What is test? • For .NET code, NUnit. – Runs on a developer’s machine and build server • What about the database? – tSQLt is an open source framework for testing SQL Server databases – SQL Test provides SSMS integration
  10. 10. #sqlinthecity Demo background Two fictional developers, David and Grant, are working on the website, www.simpletalk.com, a community website for .NET and SQL Server developers The application comprises • An ASP.Net web application • A SQL Server database
  11. 11. #sqlinthecity Demo background Continuous integration has been configured to: 1. Keep a test database up to date with the latest changes 2. Run automated tSQLt tests (on realistic amounts of data) 3. Generate up-to-date documentation 4. Generate deployment scripts
  12. 12. #sqlinthecity Demo background A few improvements are being made to Simple Talk. These changes will be deployed to production. But… only when the dev team has demonstrated that the changes work!
  13. 13. #sqlinthecity Tools used • TeamCity (CI tool from JetBrains) • SQL Automation Pack (includes TeamCity plugin) • Glimpse (open source) From the SQL Developer Bundle: • • • • SQL Source Control SQL Test (tSQLt unit testing framework) SQL Data Generator SQL Doc
  14. 14. #sqlinthecity Demo
  15. 15. Custom Migration Scripts An introduction #sqlinthecity
  16. 16. #sqlinthecity Generating a deployment script 1 12
  17. 17. #sqlinthecity How changes are made create table modify procedure 1 2 3 delete column create trigger drop view 4 5 6
  18. 18. #sqlinthecity How changes are made create table modify procedure 1 2 modify trigger create function 7 3 drop procedure 8 4 10 6 5 create view modify function 9 delete column create trigger drop view create procedure 11 12
  19. 19. #sqlinthecity How SQL Compare sees the world 1 12
  20. 20. #sqlinthecity But not all changes can be inferred 1 2 3 5 column rename merge table 8 merge column split column 9 6 add NOT NULL column without DEFAULT table rename split table 7 4 10 11 data transformation data motion 12
  21. 21. #sqlinthecity SQL Compare and SQL Source Control support custom migration scripts 1 2 3 4 5 6 11 12 Custom migration script 7 8 9 10
  22. 22. #sqlinthecity Deployment script with migration scripts 1 12
  23. 23. #sqlinthecity 1 1’ 12
  24. 24. #sqlinthecity Demo
  25. 25. #sqlinthecity Recap: database CI 1. Incrementally keeps a test database up to date 2. Runs tSQLt tests on a database with realistic amounts of data 3. Generates always-up-to-date documentation 4. Generates and validates deployment scripts 5. Publishes a Deployment Manager database package
  26. 26. #sqlinthecity Recap of demo: writing a test 1. 2. 3. 4. 5. A new test is added Continuous Integration identifies a failure We reproduce the bug locally We fix the bug and test it We commit the fix to source control
  27. 27. #sqlinthecity Recap: migration scripts 1. The fix sets the [PublishDate] column from NULL to NOT NULL 2. Grant’s “get latest” fails because existing data that has NULL values 3. The continuous integration build alerts us of the same issue 4. A migration script is added to UPDATE existing data prior to changing the column to NOT NULL 5. Get Latest becomes possible and the continuous integration build once again indicates working software
  28. 28. #sqlinthecity Latest version at : www.red-gate.com/CI David.Atkinson@red-gate.com Questions?

×