340 likes | 630 Views
DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals . DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals (Part 2) . Sachin Rekhi Program Manager Microsoft Corporation. Gert E.R. Drapers
E N D
DAT320Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals
DAT320Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals (Part 2) Sachin Rekhi Program Manager Microsoft Corporation Gert E.R. Drapers Architect/Development Manager Microsoft Corporation
Agenda • The Database Development Life Cycle • The Database Developer Story • Data Generation • Database Unit Testing • Schema Refactoring • The Power of Integration • Summary
Other Sessions • Introducing Visual Studio Team Edition for Database Professionals • DEV217 - 6/13/2006 10:15AM - 11:30AM, room: 104 ABC • Managing and Deploying your SQL Server Schemas with Visual Studio Team Edition for Database Professionals • DAT312 - 6/13/2006 1:00PM - 2:15PM, room: 156 ABC • Testing & Refactoring your Database with Visual Studio Team Edition for Database Professionals • DAT320 - 6/14/2006 8:30AM - 9:45AM, room: 160 ABC • Under the Hood of Visual Studio Team Edition for Database Professionals • DAT433 - 6/15/2006 1:00PM - 2:15PM, room: 160 ABC
Product Overview • Database Project System • Schema and Script Versioning (SCC Integration) • Schema Build & Deploy • Schema Compare • Data Compare • Database Unit Testing • (Test) Data Generator • Schema Refactoring • T-SQL Editor with Query Execution • Work Item and Process Integration with TFS
Project ModelThe center of gravity • The database project represents the “truth” with regards to schema versioning • Optionally database project can be placed under source control • .SQL script files is the canonical format used • Changes are tracked at the “object level” • For example indexes, constraints, triggers are tracked independent of the base table definition, in order have the highest granularity of change tracking
Database Development Life CycleThe cycle of life for database developers Import database schema SQLServerDatabase Database Project Template Database Project Create New Project SQL Script Reverse engineer existing .SQL script files (*) (*) Not implemented in the current CTP
Database Development Life CycleThe cycle of life for database developers Edit Refactor Compare Database Project Deploy Build Data Generation Test Compare
DeploySQLScript SQLServerDatabase Database Development Life CycleThe cycle of life for database developers Import database schema SQLServerDatabase Build project Database Project Template Database Project Create New Project Deploy project SQL Script Reverse engineer existing .SQL script files (*) (*) Not implemented in the current CTP
Continuing the Journey… • In part 1 we established: • A Database Project representing our schema • Placed it under version control • Create a sandbox environment using Build & Deploy • Verified if the sandbox matches the project and the original database, using Schema Compare • Now we are ready to start making changes! • First we are going to create test data • Which will be used by the test bed we are creating • So we can validate our changes made using Schema Refactoring
Data GenerationDesign Time • Setting up Data Generation implies defining: • Which generator to use • Which distribution to attach to the generator • Changing setting on the generator & distribution • The numbers of rows to generate • Optionally defining the rowcount ratios between tables • By default: • Each column is bound to the generator matching the column data type • FK columns are mapped to the Foreign Key generator • Uniqueness is inferred from PK, UC constraints and indexes • Using the Uniform distribution when not unique
Data GenerationDesign Time • Value generators • Simple generators for each data type • Strings: ASCII and Unicode ((var)char, n(var)char, (n)text) • Numbers: tinyint, smallint, int, bigint, real, float, decimal, numeric, money • Binary ((var)binary, image) • Date and Time • UniqueIdentifier (GUID) • Bit • Complex generators • Foreign Key, Regular Expression, Data Bound • Distributions • Uniform, Normal, Inverse Normal, Exponential, Inverse Exponential • Can import column distributions from production database (*) (*) Not implemented in the current CTP
Data GenerationDesign Time • Understand domain constraints • Check constraints (min/max) • Table cardinality • Enforce table ratios • Column value distribution
Data GenerationExecuting a Data Generation Definition • Validation of • Security requirements • Fails when security requirements are not met! • Target schema against DGEN definitions • Fails the generation when bindings do not match! • Optionally purge tables • Required to guarantee repeatable data generation • Spin up parallel streams of INSERT statements • Based on relation ships between tables • Number of connections used is currently gated by the schema relationships. • Configurable Error Thresholds
Data GenerationCustomization & Extensibility • Customization of value generation • RegEx Generator • Data Bound Generator • Extensibility • Custom Generator • Custom Distribution • Discussed in detail in: • Under the Hood of Visual Studio Team Edition for Database Professionals • DAT433 - 6/15/2006 1:00PM - 2:15PM, room: 160 ABC
Data Generation Sachin RekhiProgram Manager Visual Studio Team System
Database Unit TestingDesign Time • Automatically generate unit tests stubs for: • Stored Procedures, Functions (*), Triggers (*) • Test Validation (assertions) • T-SQL (server based) Assertions • RAISERROR command • Client Side Assertions • None Empty ResultSet • Row Count • Execution Time, … • Pre & Post Test Scripts (*) Not implemented in the current CTP
Database Unit Testing Test Execution • Automatic Deployment Integration • Automatically deploy database project prior to running tests (*) • Data Generation Integration • Automatically generate data based on generation plan prior to running tests • Execution & Validation connections • Validation connection can be higher privileged account (*) Not implemented in the current CTP
Database Unit TestingCustomization & Extensibility • Database Unit Test designer generates C# or VB.NET code • Can customize generated code for: • Custom test validation logic • Parameterized test support • Managing transactions • Additional test setup and teardown of tests • Discussed in detail in: • Under the Hood of Visual Studio Team Edition for Database Professionals • DAT433 - 6/15/2006 1:00PM - 2:15PM, room: 160 ABC
Database Unit Testing Sachin RekhiProgram Manager Visual Studio Team System
Database Schema RefactoringWhat is refactoring? • “A database refactoring is a small change to your database schema which improves its design without changing its semantics.” • Agile Database Development, Scott Ambler • For example: • Rename a Schema Object Name for consistency, understandability, maintainability… • Objective: Rename ALL schema object references; direct and indirect inside all: • Tables, views, stored procedures, user defined functions, …
Database Schema Refactoring Rename Refactoring… • Rename any SQL 2000 & SQL 2005 schema object • Updates all references in… • Schema Objects • Data Generation Plans • Scripts • Database Unit Tests • Preview changes prior to commit • Global undo to reverse all changes
Database Schema Refactoring Refactoring Safety Net • Unit Testing • Develop a battery of tests to run after a refactoring to ensure database still functions as expected • Version Control • Store all previous versions so you can always go back to a prior baseline in source control • Schema Compare • Analyze the exact differences between the project and live database to understand the impact of the update
Schema Refactoring Sachin RekhiProgram Manager Visual Studio Team System
Integrating In To The Cycle of Life Edit Refactor Compare Database Project Deploy Build Data Generation Test Compare
End-to-End Database Development Sachin RekhiProgram Manager Visual Studio Team System
Summary • Handle Schema Change Management and Deployment • Mitigate the Risks Involved with making and deploying changes • Integrate the Database Professional in to the Development Life Cycle
Resources • Break-out Sessions • Under the Hood of Visual Studio Team Edition for Database Professionals • DAT433 - 6/15/2006 1:00PM - 2:15PM, room: 160 ABC • Hands on Labs • DEV008 Take a Tour of Visual Studio 2005 Team System for Database Professionals • Chalk Talks • Visual Studio Team Edition for Database Professionals: Overview • DEV TLC Theatre 6/15/2006 9:45AM-11:00AM
Resources… • CTP 3 Download Site • http://download.microsoft.com/download/1/a/3/1a32ea84-11a3-4adf-953e-7a65b9831f5a/VSDATAD1.img • Team Website • http://msdn.microsoft.com/vstudio/teamsystem/products/dbpro/default.aspx • Product Forum • http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=725&SiteID=1 • PowerToys and Samples • http://gotdotnet.com/Workspaces/Workspace.aspx?id=378460fd-1254-427b-aa7d-e777a826a564 • Blogs • http://blogs.msdn.com/gertd
Fill out a session evaluation on CommNet for a chance to Win an XBOX 360!
© 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.