2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database...

34
  • date post

    22-Dec-2015
  • Category

    Documents

  • view

    217
  • download

    1

Transcript of 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database...

Page 1: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.
Page 2: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

22

DAT320DAT320Testing and Refactoring Your Database with Testing and Refactoring Your Database with

Visual Studio Team Edition for Database Visual Studio Team Edition for Database Professionals Professionals

Page 3: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

33

Page 4: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

44

DAT320DAT320Testing and Refactoring Testing and Refactoring Your Database with Visual Your Database with Visual Studio Team Edition for Studio Team Edition for Database Professionals Database Professionals (Part 2) (Part 2)

DAT320DAT320Testing and Refactoring Testing and Refactoring Your Database with Visual Your Database with Visual Studio Team Edition for Studio Team Edition for Database Professionals Database Professionals (Part 2) (Part 2) Sachin RekhiSachin RekhiProgram ManagerProgram ManagerMicrosoft Microsoft CorporationCorporationGert E.R. DrapersGert E.R. DrapersArchitect/Development ManagerArchitect/Development ManagerMicrosoft CorporationMicrosoft Corporation

Page 5: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

55

AgendaAgenda

The Database Development Life CycleThe Database Development Life Cycle

The Database Developer StoryThe Database Developer StoryData GenerationData Generation

Database Unit TestingDatabase Unit Testing

Schema RefactoringSchema Refactoring

The Power of IntegrationThe Power of Integration

SummarySummary

Page 6: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

66

Other SessionsOther Sessions

Introducing Visual Studio Team Edition for Introducing Visual Studio Team Edition for Database ProfessionalsDatabase Professionals

DEV217 - 6/13/2006 10:15AM - 11:30AM, room: 104 ABCDEV217 - 6/13/2006 10:15AM - 11:30AM, room: 104 ABC

Managing and Deploying your SQL Server Managing and Deploying your SQL Server Schemas with Visual Studio Team Edition for Schemas with Visual Studio Team Edition for Database ProfessionalsDatabase Professionals

DAT312 - 6/13/2006 1:00PM - 2:15PM, room: 156 ABCDAT312 - 6/13/2006 1:00PM - 2:15PM, room: 156 ABC

Testing & Refactoring your Database with Testing & Refactoring your Database with Visual Studio Team Edition for Database Visual Studio Team Edition for Database ProfessionalsProfessionals

DAT320 - 6/14/2006 8:30AM - 9:45AM, room: 160 ABCDAT320 - 6/14/2006 8:30AM - 9:45AM, room: 160 ABC

Under the Hood of Under the Hood of Visual Studio Team Edition for Database Visual Studio Team Edition for Database ProfessionalsProfessionals

DAT433 - 6/15/2006 1:00PM - 2:15PM, room: 160 ABCDAT433 - 6/15/2006 1:00PM - 2:15PM, room: 160 ABC

Page 7: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

77

Product OverviewProduct Overview

Database Project SystemDatabase Project SystemSchema and Script Versioning (SCC Integration)Schema and Script Versioning (SCC Integration)

Schema Build & DeploySchema Build & Deploy

Schema CompareSchema Compare

Data CompareData Compare

Database Unit TestingDatabase Unit Testing

(Test) Data Generator(Test) Data Generator

Schema RefactoringSchema Refactoring

T-SQL Editor with Query ExecutionT-SQL Editor with Query Execution

Work Item and Process Integration with Work Item and Process Integration with TFSTFS

Page 8: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

88

Project ModelProject ModelThe center of gravityThe center of gravity

The database project represents the The database project represents the “truth” with regards to schema versioning“truth” with regards to schema versioning

Optionally database project can be placed Optionally database project can be placed under source controlunder source control

.SQL script files is the canonical format .SQL script files is the canonical format usedused

Changes are tracked at the “object level”Changes are tracked at the “object level”For example indexes, constraints, triggers are For example indexes, constraints, triggers are tracked independent of the base table tracked independent of the base table definition, in order have the highest granularity definition, in order have the highest granularity of change tracking of change tracking

Page 9: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

99

Database Development Life Database Development Life CycleCycleThe cycle of life for database developersThe cycle of life for database developers

DatabaseDatabaseProjectProject

(*) Not implemented in the current CTP(*) Not implemented in the current CTP

Import database schemaImport database schema

Reverse engineer existing .SQL script files (*)Reverse engineer existing .SQL script files (*)

Create New ProjectCreate New Project

SQLSQLScriptScript

DatabasDatabasee

ProjectProjectTemplatTemplat

ee

SQLSQLServerServer

DatabasDatabasee

Page 10: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

1010

Database Development Life Database Development Life CycleCycleThe cycle of life for database developersThe cycle of life for database developers

DatabaseDatabaseProjectProject

EditEdit

CompareCompare

TestTest

BuildBuild

Data Data GenerationGeneration

DeployDeploy

RefactorRefactor

CompareCompare

Page 11: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

1111

Database Development Life Database Development Life CycleCycleThe cycle of life for database developersThe cycle of life for database developers

DatabaseDatabaseProjectProject

(*) Not implemented in the current CTP(*) Not implemented in the current CTP

Import database schemaImport database schema

Reverse engineer existing .SQL script files (*)Reverse engineer existing .SQL script files (*)

Create New ProjectCreate New Project

SQLSQLScriptScript

DatabasDatabasee

ProjectProjectTemplatTemplat

ee

SQLSQLServerServer

DatabasDatabasee

DeployDeploySQLSQL

ScriptScript

SQLSQLServerServer

DatabasDatabasee

Build projectBuild project

Deploy projectDeploy project

Page 12: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

1212

Continuing the Journey… Continuing the Journey…

In part 1 we established:In part 1 we established:A Database Project representing our schemaA Database Project representing our schema

Placed it under version controlPlaced it under version control

Create a sandbox environment using Build & Create a sandbox environment using Build & DeployDeploy

Verified if the sandbox matches the project and Verified if the sandbox matches the project and the original database, using Schema Comparethe original database, using Schema Compare

Now we are ready to start making Now we are ready to start making changes!changes!

First we are going to create test dataFirst we are going to create test data

Which will be used by the test bed we are Which will be used by the test bed we are creatingcreating

So we can validate our changes made using So we can validate our changes made using Schema RefactoringSchema Refactoring

Page 13: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

1313

Data GenerationData GenerationDesign TimeDesign Time

Setting up Data Generation implies Setting up Data Generation implies defining:defining:

Which generator to useWhich generator to use

Which distribution to attach to the generatorWhich distribution to attach to the generator

Changing setting on the generator & Changing setting on the generator & distributiondistribution

The numbers of rows to generateThe numbers of rows to generate

Optionally defining the rowcount ratios between Optionally defining the rowcount ratios between tablestables

By default:By default:Each column is bound to the generator Each column is bound to the generator matching the column data typematching the column data type

FK columns are mapped to the Foreign Key generatorFK columns are mapped to the Foreign Key generator

Uniqueness is inferred from PK, UC constraints and Uniqueness is inferred from PK, UC constraints and indexesindexes

Using the Uniform distribution when not uniqueUsing the Uniform distribution when not unique

Page 14: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

1414

Data GenerationData GenerationDesign TimeDesign Time

Value generatorsValue generatorsSimple generators for each data typeSimple generators for each data type

Strings: ASCII and Unicode ((var)char, n(var)char, Strings: ASCII and Unicode ((var)char, n(var)char, (n)text)(n)text)Numbers: tinyint, smallint, int, bigint, real, float, Numbers: tinyint, smallint, int, bigint, real, float, decimal, numeric, moneydecimal, numeric, moneyBinary ((var)binary, image)Binary ((var)binary, image)Date and TimeDate and TimeUniqueIdentifier (GUID)UniqueIdentifier (GUID)BitBit

Complex generatorsComplex generatorsForeign Key, Regular Expression, Data BoundForeign Key, Regular Expression, Data Bound

DistributionsDistributionsUniform, Normal, Inverse Normal, Exponential, Inverse Uniform, Normal, Inverse Normal, Exponential, Inverse ExponentialExponentialCan import column distributions from production Can import column distributions from production database (*)database (*)

(*) Not implemented in the current CTP(*) Not implemented in the current CTP

Page 15: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

1515

Data GenerationData GenerationDistributions @ WorkDistributions @ Work

Data Generation Distributions

0

2000

4000

6000

8000

10000

12000

1 501 1001 1501 2001 2501 3001 3501 4001 4501

# of Rows

Ge

ne

rate

Va

lue

(0

-10

00

0)

Uniform

Normal

InverseNormal

Exponential

InverseExponential

Page 16: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

1616

Data GenerationData GenerationDesign TimeDesign Time

Understand domain constraintsUnderstand domain constraintsCheck constraints (min/max)Check constraints (min/max)

Table cardinalityTable cardinalityEnforce table ratiosEnforce table ratios

Column value distributionColumn value distribution

Page 17: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

1717

Data GenerationData GenerationExecuting a Data Generation DefinitionExecuting a Data Generation Definition

Validation ofValidation ofSecurity requirementsSecurity requirements

Fails when security requirements are not met!Fails when security requirements are not met!

Target schema against DGEN definitionsTarget schema against DGEN definitionsFails the generation when bindings do not match!Fails the generation when bindings do not match!

Optionally purge tablesOptionally purge tablesRequired to guarantee repeatable data Required to guarantee repeatable data generationgeneration

Spin up parallel streams of INSERT Spin up parallel streams of INSERT statementsstatements

Based on relation ships between tablesBased on relation ships between tables

Number of connections used is currently gated Number of connections used is currently gated by the schema relationships.by the schema relationships.

Configurable Error ThresholdsConfigurable Error Thresholds

Page 18: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

1818

Data GenerationData GenerationCustomization & Extensibility Customization & Extensibility

Customization of value generationCustomization of value generationRegEx GeneratorRegEx Generator

Data Bound GeneratorData Bound Generator

ExtensibilityExtensibilityCustom GeneratorCustom Generator

Custom DistributionCustom Distribution

Discussed in detail in:Discussed in detail in:Under the Hood of Visual Studio Team Edition Under the Hood of Visual Studio Team Edition for Database Professionalsfor Database Professionals

DAT433 - 6/15/2006 1:00PM - 2:15PM, room: 160 ABCDAT433 - 6/15/2006 1:00PM - 2:15PM, room: 160 ABC

Page 19: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

1919

Sachin RekhiSachin RekhiProgram ManagerProgram ManagerVisual Studio Team SystemVisual Studio Team System

Data GenerationData GenerationData GenerationData Generation

Page 20: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

2020

Database Unit TestingDatabase Unit TestingDesign TimeDesign Time

Automatically generate unit tests stubs for:Automatically generate unit tests stubs for:Stored Procedures, Functions (*), Triggers (*)Stored Procedures, Functions (*), Triggers (*)

Test Validation (assertions)Test Validation (assertions)T-SQL (server based) AssertionsT-SQL (server based) Assertions

RAISERROR commandRAISERROR command

Client Side AssertionsClient Side AssertionsNone Empty ResultSetNone Empty ResultSet

Row Count Row Count

Execution Time, …Execution Time, …

Pre & Post Test ScriptsPre & Post Test Scripts

(*) Not implemented in the current CTP(*) Not implemented in the current CTP

Page 21: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

2121

Database Unit Testing Database Unit Testing Test ExecutionTest Execution

Automatic Deployment IntegrationAutomatic Deployment IntegrationAutomatically deploy database project prior to Automatically deploy database project prior to running tests (*)running tests (*)

Data Generation IntegrationData Generation IntegrationAutomatically generate data based on Automatically generate data based on generation plan prior to running testsgeneration plan prior to running tests

Execution & Validation connectionsExecution & Validation connectionsValidation connection can be higher privileged Validation connection can be higher privileged accountaccount

(*) Not implemented in the current CTP(*) Not implemented in the current CTP

Page 22: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

2222

Database Unit TestingDatabase Unit TestingCustomization & ExtensibilityCustomization & Extensibility

Database Unit Test designer generates C# Database Unit Test designer generates C# or VB.NET codeor VB.NET code

Can customize generated code for:Can customize generated code for:Custom test validation logicCustom test validation logic

Parameterized test supportParameterized test support

Managing transactionsManaging transactions

Additional test setup and teardown of testsAdditional test setup and teardown of tests

Discussed in detail in:Discussed in detail in:Under the Hood of Visual Studio Team Edition Under the Hood of Visual Studio Team Edition for Database Professionalsfor Database Professionals

DAT433 - 6/15/2006 1:00PM - 2:15PM, room: 160 ABCDAT433 - 6/15/2006 1:00PM - 2:15PM, room: 160 ABC

Page 23: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

2323

Sachin RekhiSachin RekhiProgram ManagerProgram ManagerVisual Studio Team SystemVisual Studio Team System

Database Unit TestingDatabase Unit TestingDatabase Unit TestingDatabase Unit Testing

Page 24: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

2424

Database Schema RefactoringDatabase Schema RefactoringWhat is refactoring?What is refactoring?

““A database refactoring is a small change A database refactoring is a small change to your database schema which improves to your database schema which improves its design without changing its semantics.”its design without changing its semantics.”

Agile Database Development, Scott AmblerAgile Database Development, Scott Ambler

For example:For example:Rename a Schema Object Name for Rename a Schema Object Name for consistency, understandability, consistency, understandability, maintainability…maintainability…

Objective: Rename Objective: Rename ALLALL schema object schema object references; direct and indirect inside all:references; direct and indirect inside all:

Tables, views, stored procedures, user defined Tables, views, stored procedures, user defined functions, …functions, …

Page 25: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

2525

Database Schema Refactoring Database Schema Refactoring Rename Refactoring…Rename Refactoring…

Rename any SQL 2000 & SQL 2005 Rename any SQL 2000 & SQL 2005 schema objectschema object

Updates all references in…Updates all references in…Schema ObjectsSchema Objects

Data Generation Plans Data Generation Plans

ScriptsScripts

Database Unit TestsDatabase Unit Tests

Preview changes prior to commitPreview changes prior to commit

Global undo to reverse all changesGlobal undo to reverse all changes

Page 26: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

2626

Database Schema Refactoring Database Schema Refactoring Refactoring Safety NetRefactoring Safety Net

Unit TestingUnit TestingDevelop a battery of tests to run after a Develop a battery of tests to run after a refactoring to ensure database still functions as refactoring to ensure database still functions as expectedexpected

Version ControlVersion ControlStore all previous versions so you can always Store all previous versions so you can always go back to a prior baseline in source controlgo back to a prior baseline in source control

Schema CompareSchema CompareAnalyze the exact differences between the Analyze the exact differences between the project and live database to understand the project and live database to understand the impact of the updateimpact of the update

Page 27: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

2727

Sachin RekhiSachin RekhiProgram ManagerProgram ManagerVisual Studio Team SystemVisual Studio Team System

Schema RefactoringSchema RefactoringSchema RefactoringSchema Refactoring

Page 28: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

2828

Integrating In To The Cycle of LifeIntegrating In To The Cycle of Life

DatabaseDatabaseProjectProject

EditEdit

CompareCompare

TestTest

BuildBuild

Data Data GenerationGeneration

DeployDeploy

RefactorRefactor

CompareCompare

Page 29: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

2929

Sachin RekhiSachin RekhiProgram ManagerProgram ManagerVisual Studio Team SystemVisual Studio Team System

End-to-End Database End-to-End Database DevelopmentDevelopmentEnd-to-End Database End-to-End Database DevelopmentDevelopment

Page 30: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

3030

SummarySummary

Handle Schema Change Management and Handle Schema Change Management and DeploymentDeployment

Mitigate the Risks Involved with making Mitigate the Risks Involved with making and deploying changesand deploying changes

Integrate the Database Professional in to Integrate the Database Professional in to the Development Life Cyclethe Development Life Cycle

Page 31: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

3131

ResourcesResources

Break-out SessionsBreak-out SessionsUnder the Hood of Visual Studio Team Edition Under the Hood of Visual Studio Team Edition for Database Professionalsfor Database Professionals

DAT433 - 6/15/2006 1:00PM - 2:15PM, room: 160 ABCDAT433 - 6/15/2006 1:00PM - 2:15PM, room: 160 ABC

Hands on LabsHands on LabsDEV008 Take a Tour of Visual Studio 2005 DEV008 Take a Tour of Visual Studio 2005 Team System for Database ProfessionalsTeam System for Database Professionals

Chalk TalksChalk TalksVisual Studio Team Edition for Database Visual Studio Team Edition for Database Professionals: Overview Professionals: Overview

DEV TLC Theatre 6/15/2006 9:45AM-11:00AMDEV TLC Theatre 6/15/2006 9:45AM-11:00AM

Page 32: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

3232

Resources…Resources…

CTP 3 Download SiteCTP 3 Download Sitehttp://download.microsoft.com/download/1/a/3/1a32ea84http://download.microsoft.com/download/1/a/3/1a32ea84-11a3-4adf-953e-7a65b9831f5a/VSDATAD1.img-11a3-4adf-953e-7a65b9831f5a/VSDATAD1.img

Team WebsiteTeam Websitehttp://msdn.microsoft.com/vstudio/teamsystem/products/http://msdn.microsoft.com/vstudio/teamsystem/products/dbpro/default.aspxdbpro/default.aspx

Product ForumProduct Forumhttp://forums.microsoft.com/MSDN/ShowForum.aspx?Forhttp://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=725&SiteID=1umID=725&SiteID=1

PowerToys and SamplesPowerToys and Sampleshttp://gotdotnet.com/Workspaces/Workspace.aspx?id=37http://gotdotnet.com/Workspaces/Workspace.aspx?id=378460fd-1254-427b-aa7d-e777a826a5648460fd-1254-427b-aa7d-e777a826a564

BlogsBlogshttp://http://blogs.msdn.com/gertdblogs.msdn.com/gertd

Page 33: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

3333

Fill out a session Fill out a session evaluation on evaluation on CommNet for CommNet for

a chance toa chance toWin an XBOX Win an XBOX

360!360!

Page 34: 2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.

© 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.