PHX - Session #4 Treating Databases as First-Class Citizens in Development

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Event

    PHX - Session #4 Treating Databases as First-Class Citizens in Development - Presentation Transcript

    1. Treating Databases as First- Class Citizens in Development Rob Bagby Developer Evangelist Microsoft Corporation www.RobBagby.com Rob.Bagby@Microsoft.com
    2. Agenda Overview The Database Project (Test) Data Generation Unit Tests Managing Change Q&A
    3. Some Important Questions • Where is the “truth” for my schema? – Production? – What about bug fixes? – What about version next? How do I version my databases? • What do I do for test data? • How do I test my database logic? • What tools do I use to differentiate • schemas, data?
    4. Challenge Solution • Multiple Truths, stored • Where’s the truth? offline • The same way I version • How do I version? source code • Where do I get test data? • Test Data Generator • How do I unit test? • The same way I test source code (with a little SQL love thrown in) • What tools do I have to • Schema Compare, Data manage change? Compare, Refactoring
    5. The “Truth” of my schema • The production DB is only 1 version of the truth of your schema • There may be bug fixes in Q/A right now, waiting deployment • There may be development going on right now by multiple developers / teams
    6. Project Model • The database project represents the “truth” of your schema • The project contains the schema (*.sql files) • Use version control to manage different versions
    7. Database Development Lifecycle SQL Server Database Database Project Database Project Template SQL Script
    8. Database Development Lifecycle Edit Refactor Compare Deploy Build Database Project Data Gen Test Compare
    9. Version Control Challenge class class class AuctionApplication AuctionApplication AuctionApplication App ( ( ( int id; id; int int id; void MethodA(); void MethodA(); string cacheTitle; void MethodB(); void MethodA(); ) ) void MethodB(); ) V3 Revision History V2 V1 CREATE TABLE dbo.Auction ALTER ALTER TABLE dbo.Auction TABLE dbo.Auction Database ( WITH CHECK CHECK ADD CONSTRAINT WITH ADD CONSTRAINT id INT NOT NULL, KEY (id) Au_PK Au_SK UNIQUE (name) PRIMARY name VARCHAR(25) NOT NULL, start DATETIME NULL, len INT NULL )
    10. Manual Versioning -- version 1 Add table dbo.Auction IF OBJECT_ID (N'dbo.Auction', N'U') IS NULL BEGIN CREATE TABLE dbo.Auction ( id INT NOT NULL, name VARCHAR(25) NOT NULL, start DATETIME NULL, len INT NULL ) END -- version 2 Add PK Au_PK IF NOT EXISTS (SELECT * FROM sys.key_constraints WHERE name = 'Au_PK' AND type = 'PK') BEGIN ALTER TABLE Auction WITH CHECK ADD CONSTRAINT Au_PK PRIMARY KEY (id) END -- version 3 Add UC Au_SK IF NOT EXISTS (SELECT * FROM sys.key_constraints WHERE name = 'Au_SK' AND type = ‘UQ') BEGIN ALTER TABLE Auction WITH CHECK ADD CONSTRAINT Au_SK UNIQUE (name) END
    11. Version Control The “Data dude” approach class class class AuctionApplication AuctionApplication AuctionApplication App ( ( ( int id; id; int int id; void MethodA(); void MethodA(); string cacheTitle; ) void MethodB(); void MethodA(); ) void MethodB(); ) V2 V3 Revision History V1 CREATE TABLE TABLE TABLE dbo.Auction CREATE dbo.Auction CREATE dbo.Auction Logical ( ( ( Database id id INT NOT NULL, NULL PRIMARY KEY, KEY, id INT NOT NOT NULL PRIMARY INT name name name VARCHAR(25) NOT NULL UNIQUE, VARCHAR(25) NOT NULL, NULL, VARCHAR(25) NOT start start start DATETIME NULL, DATETIME NULL, NULL, DATETIME len len NULL NULL NULL INT len INT INT ) ) )
    12. Deployment The “Data dude” approach CREATE TABLE TABLE TABLE dbo.Auction CREATE dbo.Auction CREATE dbo.Auction Logical ( ( ( Database id id INT NOT NULL, NULL PRIMARY KEY, KEY, id INT NOT NOT NULL PRIMARY INT name name name VARCHAR(25) NOT NULL UNIQUE, VARCHAR(25) NOT NULL, NULL, VARCHAR(25) NOT start start start DATETIME NULL, DATETIME NULL, NULL, DATETIME len len NULL NULL NULL INT len INT INT ) ) ) V2 V3 Revision History V1 New Incremental CREATE TABLE dbo.Auction ALTER TABLE dbo.Auction Deployment Deployment ( WITH CHECK ADD CONSTRAINT id INT NOT NULL PRIMARY KEY, Au_SK UNIQUE (name) name VARCHAR(25) NOT NULL UNIQUE, start DATETIME NULL, len INT NULL )
    13. demo The Project Model
    14. Agenda Overview The Database Project (Test) Data Generation Unit Tests Managing Change Q&A
    15. Test Data Q & A • Why not production data? – Ahhh, it may be illegal – Doesn’t test edge cases – Doesn’t address schema changes • What are our test data requirements? – “Random” – Deterministic – Appropriately distributed –…
    16. Test Data Q & A (continued) • What are the differing needs for test data? – Functional Test – Load Test • What are the versioning implications – We need differing plan(s) for differing schemas – We need to version plans along side schemas
    17. (Test) Data Generation in VSTS Choose the following • The Tables • Number of rows (RowCount ratios help) • The generator for each column Out of the box: string, RegEx, data bound, etc. – Write your own – Set generator-specific settings – Set the seed – provides determinism – • The distribution
    18. demo (Test) Data Generation
    19. Agenda Overview The Database Project (Test) Data Generation Unit Tests Managing Change Q&A
    20. Database Unit Testing • Automatically generate unit test 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 and Post Test Scripts
    21. Database Unit Testing • 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
    22. demo Database Unit Tests
    23. Agenda Overview The Database Project (Test) Data Generation Unit Tests Managing Change Q&A
    24. What kind of change can we manage? • Refactoring • Compare schemas • Compare data
    25. demo Managing Change
    SlideShare Zeitgeist 2009

    + Steve LangeSteve Lange Nominate

    custom

    237 views, 0 favs, 1 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 237
      • 236 on SlideShare
      • 1 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 2
    Most viewed embeds
    • 1 views on http://blogs.msdn.com

    more

    All embeds
    • 1 views on http://blogs.msdn.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Tags