sql source control

24
Click here to _START_ GET YER DATA UNDER SOURCE CONTROL!

Upload: andypickett

Post on 07-Feb-2015

1.231 views

Category:

Technology


6 download

DESCRIPTION

Slides for Twin Cities and Iowa Code Camp Talk - Get you SQL under source control.

TRANSCRIPT

Page 1: Sql source control

Click here to _START_

GET YER DATA UNDER SOURCE

CONTROL!

Page 2: Sql source control

• Lead Game Designer/Dev - QONQR

• Independent Consultant – MS Stack

• Leadership Team – Twin Cities Code Camp

• Co-Leader – Twin Cities .Net User Group

• Level 80 Draenei Enhancement Shaman (retired)

• (@apickett != Accountant || Lawyer || Fortune Teller || Diamond Level Starcraft II)

about.me

Page 3: Sql source control

I can haz Shared Dev DB?

Page 4: Sql source control

Local Dev DBs = happy devs :D

Page 5: Sql source control

…Until Integration timez

Page 6: Sql source control

• SQL under Source Control• Check in Schema, Ref Data, Migration Scripts

• Revision History

• Merge Conflicts

• Database Continuous Integration & Deploy• Automated Builds

• Automated Database Deploy

• from Source Control to target environment

What we’ll cover20% effort

BIG REWARD!

80% effortMEGA REALLY

HUGE REWARD!

Page 7: Sql source control

• 1. Never use a shared database server for development work.

• 2. Always Have a Single, Authoritative Source For Your Schema

• 3. Always Version Your Database

http://odetocode.com/blogs/scott/archive/2008/01/30/three-rules-for-database-work.aspx

K. Scott Allen – Three Rules for DB work

Page 8: Sql source control

• Same as putting ur codez in SC!• Freedom to refactor (safely with rollbacks)

• Rapid iteration & integration

• Check in logs & history

• Schema Compare

• Data Compare

• Automated builds and integration tests (correctness)

• Via Coding Horror: Is Your Database Under Version Control?

http://www.codinghorror.com/blog/2006/12/is-your-database-under-version-control.html

Benefits of DB Source Control

Page 9: Sql source control

As devs we’re wizards capable of magicing up anything.

Friendly adivce: Avoid that temptation (unless it’s your core business)

- Team of 8. ½ a Dev year to maintain and extend custom rolled solution

Build vs Buy

Page 10: Sql source control

Microsoft 1st party

Page 11: Sql source control

• VS Database projects• VS 2010

• Database Project (.dbproj)

• Server Project

• Data-tier Application (DAC)

• http://msdn.microsoft.com/en-us/library/ee240739(SQL.105).aspx

• VS2011 = .sqlproj

• Moving to Sql Server Developer tools (SSDT) code named "Juneau".

• http://msdn.microsoft.com/en-us/magazine/hh394146.aspx

• VS Schema compare• Requires Visual Studio Premium or Ultimate

• Command Line VSDBCMD.EXE

Microsoft 1st party

Page 12: Sql source control

• Dacpac• Serializes DB schema to XML (?)

• Versionable, but tricky to do diffs (?)

• Targeted at managing handoff of schema between Dev and Prod

• Think similar to how IT systems hands off VMs

• http://www.slideshare.net/andrewmatthewthompson/sql-aure-and-datatier-applications-dacpac

• Bacpac• Extends Dacpac to include Table Data

Microsoft 1st party

Page 13: Sql source control

Red Gate SQL Compare rom $295.

DB Ghost from $195, recommended by Mike Hadlow here

SQL Change Manager $995 per instance.

SQL Effects Clarity standard ed. from $139; community ed. free.

SQLSourceSafe from $129.

sqlXpress Diff contact for price. :-(

Embarcadero Change Manager contact for price. :-(

Apex SQL Diff from $399

SQL Source Control 2003 from $199

SASSI v2.0 professional from $180 (looks free on their site, but apparently isn't)

Evorex Source # shareware or $299+ (conflicting reports!)

DB maestro

Via http://secretgeek.net/dbcontrol.asp (2006!)

Off the shelf

Page 14: Sql source control

Enter Redgate SQL Source Control

Page 15: Sql source control

• Sql Source Control (~$250 per seat)

• Sql Toolbelt (~$1500 per seat)• Sql Compare

• Sql Data Compare

• Sql Data Generator

• Sql Azure Backup (free)

Redgate20% effort AND cost!

80% effort and cost

(but worth it!)

Page 16: Sql source control

DEMO!

Page 17: Sql source control

Conflicts

Page 18: Sql source control

• Build Scripting• MSBuild

• Nant

• Powershell

• CI build servers• Team City

• Cruise Control

• Jenkins (formerly Hudson)

• Team Foundation Server

Continuous Integration

Page 19: Sql source control

Web Projects

• MS Web Deploy

• Windows Server (Web Management Service - WMSVC)

• Windows 7/Vista/XP (MsDepSvc)

• Different on IIS 6 vs 7

Continuous Deployment (Web)

Page 20: Sql source control

Team City -> Auto Deploy Data

Build step 1) Deploy schema

C:\Program Files (x86)\Red Gate\SQL Compare 9\SQLCompare.exe

/scr1:%teamcity.build.checkoutDir%/Data /server2:(local) /db2:tccc12_prod /Sync /Include:identical /Report:Report/SchemaDiffReport.html /ReportType:Interactive /ScriptFile:Report/SchemaSyncScript.sql /Force /Verbose

-------------------

Build step 2)

Deploy Reference Data

C:\Program Files (x86)\Red Gate\SQL Data Compare 9\SQLDataCompare.exe

/scr1:%teamcity.build.checkoutDir%/Data /server2:(local) /db2:tccc12_prod /Sync /Include:table:Country /Include:identical /ScriptFile:Report/DataSyncScript.sql /Force /Verbose

Continuous Deployment (Data)

Page 21: Sql source control

Team City - Version Control settings

Page 22: Sql source control

Mother of all builds vs Linked Build

Page 23: Sql source control

Job 1: Get your Sql under Source Control!

Job 2: Get Sql into your CI builds!

Job 3: Test your Data continuously!

Job 4: Deploy continually!

Job 5: Profit!

Take aways

Page 24: Sql source control

Online

• K Scott Allen: Three Rules for Database Work:• http://odetocode.com/blogs/scott/archive/2008/01/30/three-rules-for-

database-work.aspx

• Coding Horror: Is Your Database Under Version Control?• http://www.codinghorror.com/blog/2006/12/is-your-database-under-version-

control.html

• Troy Hunt – Rocking your SQL Source Control world with Red Gate• http://www.troyhunt.com/2010/07/rocking-your-sql-source-control-

world.html

• http://www.troyhunt.com/2011/02/automated-database-releases-with.html

Vendors

• Microsoft

• Redgate

Resources