44

Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Embed Size (px)

Citation preview

Page 1: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302
Page 2: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Database Schema Versioning with Microsoft Visual Studio Team System for Database Professionals

Dr Greg LowSenior Consultant – Readify Pty Ltd

DAT302

Page 3: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Who am I?

Senior Consultant ReadifyHost of SQL Down Under PodcastMicrosoft MSDN Regional DirectorMicrosoft MVP for SQL ServerCo-organizer of CodeCampOzOrganizer of SQL Down Under CodeCampAuthor with Rational Press

Page 4: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Introduction to Visual Studio Team Edition for Database Professionals (aka DataDude)

The Project System

Unit Tests

Session Objectives and Agenda

Building and Deploying

What’s Coming Next?

Page 5: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Project Based Development

Disconnected Project ModelVisual Studio basedTeam Collaboration via TFS

Work Item TrackingProcess Integration

Page 6: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Automated Change Support

Comparison ToolsSchemaData

Source/Version ControlRefactoring

Limited as yetRename ObjectPower Tools add more

Page 7: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Unit Testing

VSTS Test Project InfrastructureData Generation

Auto-generationHistogram-basedUnderstands foreign key relationships

ExtensibleData GeneratorsTest Assertions

Page 8: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Build / Deployment

MSBuild IntegrationCreate New DBUpdate an Existing Schema

Page 9: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Introduction to Visual Studio Team Edition for Database Professionals (aka DataDude)

The Project System

Unit Tests

Session Objectives and Agenda

Building and Deploying

What’s Coming Next?

Page 10: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

What is the source of truth?

Page 11: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Database Development Life Cycle

DatabaseProject

Import database schema

Reverse engineer existing .SQL script files

Create New Project

SQLScript

Database

ProjectTemplat

e

SQLServer

Database

Collection of .SQL file

containing T-SQL DDL fragments

Page 12: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Offline Schema Model

Parsing = SqlCodeDombased on Abstract Syntax Trees

Interpretation of Schema ModelSymbol listObject References (hard and soft dependencies)

.SQL Source

Parse

SqlCodeDom

Interpret

Schema Model

Page 13: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Database Development Life Cycle

DatabaseProject

Edit

Compare

Test

Build

Data Generation

Deploy

Refactor

Compare

Page 14: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Database Development Life Cycle

DatabaseProject

Import database schema

Reverse engineer existing .SQL script files

Create New Project

SQLScript

Database

ProjectTemplat

e

SQLServer

Database

DeploySQL

Script

SQLServer

Database

Build project

Deploy project

Page 15: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Project Model Summary

Database project = “truth” with regards to schema versioningCan be placed under source control.SQL script file is the canonical format usedChanges are tracked at object level

Indexes, constraints, triggers tracked independently of base tableProvides high granularity for change tracking

Page 16: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Build and Deploy the Project

demo

Page 17: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Introduction to Visual Studio Team Edition for Database Professionals (aka DataDude)

The Project System

Unit Tests

Session Objectives and Agenda

Building and Deploying

What’s Coming Next?

Page 18: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Data Generation

Where does test data come from?Production data?Scrubbed production data?Typed in manually?Auto-generated?

Page 19: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Unit Tests

Have been hard to do with databasesSQL 2k5 Database Snapshots helpfulLeverage VSTS Unit Test InfrastructureExtensible test assertions

Page 20: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Data Generation and Unit Tests

demo

Page 21: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Introduction to Visual Studio Team Edition for Database Professionals (aka DataDude)

The Project System

Unit Tests

Session Objectives and Agenda

Building and Deploying

What’s Coming Next?

Page 22: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Build Cycle

DBA

DBDev

ProductionDatabase

StagingDatabase

SCM

Daily Build Test

Get Latest

TestDatabase

DailyBuild

Output

Can also beused in a “Continuous”build environment

Trust Boundary

Page 23: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Deploy The Project Environment

DBA

Sync fro

m La

bel

DBDev

ProductionDatabase

StagingDatabase

SCM

SQLDeploy ScriptBuild

Deploy

Refine deploy scriptVerify

Trust Boundary

DatabaseProject

Page 24: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Benefits of This Approach

Managed, project oriented evolution of

database schemaApplication and database schema are managed togetherWork in “isolation”, deploying only when changes verifiedLeverage VSTS work item tracking and process guidance increases team collaboration and unity

Page 25: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Build & Deploy

DatabaseProject

TargetDatabas

e

SQLScript

Deploy

Build

Difference based build script

Project State“What you want”

Current State“How it is right

now”

Execute Incremental Update

Script

Page 26: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Command Line Building

All steps are implemented as MSBuild tasks

SqlBuildTaskSqlDeployTaskDataGeneratorTask

More tasks coming in Power ToolsAll project properties can be overwritten at the command line

Page 27: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Command Line Build

Using the project settings:msbuild NorthwindOnline.dbproj /t:build

Overwriting project settingsmsbuild NorthwindOnline.dbproj /t:build /p:TargetConnectionString="Data Source=(local)\sql80;Integrated Security=True;Pooling=False;" /p:TargetDatabase="NorthwindOnlineTestDB"

Page 28: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Command Line Deployment

Using the project settings:msbuild NorthwindOnline.dbproj /t:deploy

Overwriting project settings:msbuild NorthwindOnline.dbproj /t:deploy /p:TargetConnectionString="Data Source=(local)\sql80;Integrated Security=True;Pooling=False;"/p:TargetDatabase="NorthWind"

Page 29: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Provisioning Multiple Servers

How can I deploy to multiple targets?The Database Project only understand a single target server/database at the time

for each server+database combination in list{

SqlBuildTask SqlDeployTask

}

Page 30: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Building from the Command Line

demo

Page 31: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Team Foundation Build

Build Server infrastructureFully integrates with Team Foundation ServerExtensible

Based on MSBuildFully extensible XML-based scriptingRich Command-line supportRemote and Desktop build support

Have to install Team Build separatelyNot installed as part of Team Foundation Server

Page 32: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Team Foundation Build ArchitectureTF Client

Team Build Client

Team Build

Team BuildStore

Build Server

Source Control

Build Configuration files - MSBuild Scripts

MSBuild Scripts

and targets

Build sources and scripts

Build Events

Build events

Build request and Reports

Team Build Service

Team Build logger Build and

Test data

Build start/stop

Work item Tracking

Open and Update bugs

BuildDrop site

TFS Data Tier

TF Warehouse

Static Analysis& Testing

TFS

Page 33: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Introduction to Visual Studio Team Edition for Database Professionals (aka DataDude)

The Project System

Unit Tests

Session Objectives and Agenda

Building and Deploying

What’s Coming Next?

Page 34: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Service Pack 1

Now downloadable

Page 35: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Power Tools

New RefactoringsMove schemaDisambiguate (fully aliases references)Wild-card expansion (*)Generated schema deployment scripts based on refactoring logs (separates sp_name and TRANSFER SCHEMA)Strongly-typed dataset refactoring (if in same solution file)

Page 36: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Power Tools

New MSBuild TasksSchema compareData Compare

Data GeneratorRegular expression string and data bound generatorsRegex editor has generator for check constraintsStream-based data-bound generator (pulls one row at a time)

Page 37: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Power Tools

Dependency Tree ViewerT-SQL Static Code Analysis (ala FxCop)API Access to Schema View

Leveraged by CA Erwin R7.2 SQL Script Pre-Processor

Expands variables and include files

Page 38: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Summary

Excellent addition to VSTSAllows database schemas and versioning to be managed along with application codeExtensible

Page 39: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

ResourcesMSDN Forum: Visual Studio Team System - Database Professionals

http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=725&SiteID=1

White papersWhat Microsoft Visual Studio 2005 Team Edition for Database Professionals Can Do for YouA Security Overview of Microsoft Visual Studio 2005 Team Edition for Database ProfessionalsDatabase Unit Testing with Team Edition for Database Professionals

Sampleshttp://www.codeplex.com/vsdbpro

Trial Editionhttp://www.microsoft.com/downloads/details.aspx?familyid=7de00386-893d-4142-a778-992b69d482ad&displaylang=en

Gert’s Bloghttp://blog.msdn.com/gertd

Page 40: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

SQL Down Under Code Camp

Biggest SQL Server community event in Australia14 SQL Server sessions over two daysSpecial guest presentation from Kevin Kline

President of PASS, Director of Technology – Quest Software

When?Weekend of the 13th and 14th of October

Where?Charles Sturt University, Wagga Wagga

What does it cost?This event is FREE

http://www.sqldownunder.com

Page 41: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

SQL Server User Groups

Best place to learn about SQL Server for FREEUser Groups in most capital citiesGreat networking opportunityhttp://www.sqlserver.org.au

Page 42: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

Evaluation Forms

Page 43: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

[email protected]://msmvps.com/greglowhttp://www.sqldownunder.com

Questions?

Thank You!

Page 44: Dr Greg Low Senior Consultant – Readify Pty Ltd DAT302

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