Your SlideShare is downloading. ×
0
Database Version Control Without Pain




                           Harrie Verveer
                          June 11th 20...
Database Version Control
What’s the problem?




                           2
http://www.sxc.hu/photo/754535
http://www.sxc.hu/photo/1207911
http://en.wikipedia.org/wiki/File:STS120LaunchHiRes.jpg
http://www.sxc.hu/photo/1255121
Why Database Version Control




                               7
Simple Patching Strategy
The basic idea




                           8
Simple patching strategy




                           9
Example patch file

patch-001.sql




                     10
http://www.sxc.hu/photo/1214820
Simple patching strategy

                      Development
                            Write code
                       ...
Fixing patches

patch-002.sql




                 13
Fixing patches

patch-002.sql




                 13
Fixing patches

patch-002.sql




                 13
Fixing patches

patch-003.sql




                 14
Fixing patches

patch-003.sql




     Never modify a patch file once
       it’s under version control


                ...
Undo patch files

undo-001.sql




                   15
http://www.freefoto.com/preview/41-07-7
Bonus points




               Install.sql




                             17
Bonus points




         Initial dummy content




                                 18
http://www.sxc.hu/photo/643214
http://www.sxc.hu/photo/946855
Automating the process
Faster & Safer




                         21
http://www.sxc.hu/photo/314594
Typical patch script




                       23
Typical patch script

update.sh




                       24
http://www.sxc.hu/photo/1196126
Branches
Merge problems




                 26
Branches
Trunk
    patch-001.sql

    patch-002.sql


    patch-003.sql




                    27
Branches
Trunk
    patch-001.sql

    patch-002.sql


    patch-003.sql
                         Branch A
         create ...
Branches
Trunk
    patch-001.sql

    patch-002.sql


    patch-003.sql
                         Branch A
         create ...
Branches
Trunk
    patch-001.sql                             Branch A
                         create branch
    patch-002...
Separate sequence

db/patches/trunk/   db/patches/branchA/

patch-001.sql       patch-001.sql
patch-002.sql       patch-00...
Separate sequence

db/patches/trunk/           db/patches/branchA/

patch-001.sql               patch-001.sql
patch-002.sq...
Patchfile naming




       patch_20100611_1430.sql




                                 31
Patch log




            32
http://www.sxc.hu/photo/692740
Phing & DB Deploy
Avoiding the NIH syndrome




                            34
http://phing.info/




                     35
Phing




        36
37
DB Deploy




            38
DB Deploy

db/patches/1-create_user_table.sql




                                     39
Phing & DB Deploy




                    40
DB Deploy

changelog table:




                   41
DB Deploy

changelog table:




                   41
DB Deploy




            PHP




                  42
DB Deploy




            SQL




                  43
DB Deploy




            Features




                       44
Liquibase
A different approach




                       45
Liquibase




            www.liquibase.org




                                46
Liquibase




            47
Liquibase




            48
Liquibase




            49
Liquibase

  Updating
  Reverting
  Tagging
  Generate XML
  Diff




                 50
http://www.sxc.hu/photo/1241520
Liquibase




            Branches




                       52
Liquibase




            DBMS Support




                           53
Liquibase




            Documentation




                            54
Liquibase




            Java




                   55
Akrabat DB Schema Manager
Zend Framework specific solution




                                   56
Akrabat DB Schema Manager

  Zend Framework
  Proposed by Rob Allen in 2006
  Recently implemented
  Might be in ZF in the...
Writing the patch

scripts/migrations/001-CreateUserTable.php




                                             58
Writing the patch

scripts/migrations/001-CreateUserTable.php




                                             59
Akrabat DB Schema Manager




              PHP Patches




                            60
Akrabat DB Schema Manager




      Easy syntax if you know ZF




                                   61
Akrabat DB Schema Manager




              Easy to use




                            62
Akrabat DB Schema Manager




            Branch merging




                             63
Doctrine Migrations




                      64
Doctrine Migrations




         http://www.doctrine-project.org/




                                            65
Doctrine Migrations




                      66
Doctrine Migrations




            Update-to-version




                                67
Doctrine Migrations




             Generate patches




                                68
Doctrine Migrations




 Useful if you’re already using Doctrine
                   ORM




                              ...
Summary




          70
Summary

 Patchfiles                 Akrabat DB Schema Manager
                            http://akrabat.com
 • Automatin...
Questions ?




              72
Contact me

Harrie Verveer
Software Engineer at Ibuildings


E-mail:
harrie@ibuildings.nl


Skype:
harrie-ibuildings


Twi...
Upcoming SlideShare
Loading in...5
×

Database version control DPC version

4,566

Published on

Slides as used on the Dutch PHP Conference 2010

Published in: Technology

Transcript of "Database version control DPC version"

  1. 1. Database Version Control Without Pain Harrie Verveer June 11th 2010
  2. 2. Database Version Control What’s the problem? 2
  3. 3. http://www.sxc.hu/photo/754535
  4. 4. http://www.sxc.hu/photo/1207911
  5. 5. http://en.wikipedia.org/wiki/File:STS120LaunchHiRes.jpg
  6. 6. http://www.sxc.hu/photo/1255121
  7. 7. Why Database Version Control 7
  8. 8. Simple Patching Strategy The basic idea 8
  9. 9. Simple patching strategy 9
  10. 10. Example patch file patch-001.sql 10
  11. 11. http://www.sxc.hu/photo/1214820
  12. 12. Simple patching strategy Development Write code Write DB patches Apply patches to own DB Apply patches Commit Update 12
  13. 13. Fixing patches patch-002.sql 13
  14. 14. Fixing patches patch-002.sql 13
  15. 15. Fixing patches patch-002.sql 13
  16. 16. Fixing patches patch-003.sql 14
  17. 17. Fixing patches patch-003.sql Never modify a patch file once it’s under version control 14
  18. 18. Undo patch files undo-001.sql 15
  19. 19. http://www.freefoto.com/preview/41-07-7
  20. 20. Bonus points Install.sql 17
  21. 21. Bonus points Initial dummy content 18
  22. 22. http://www.sxc.hu/photo/643214
  23. 23. http://www.sxc.hu/photo/946855
  24. 24. Automating the process Faster & Safer 21
  25. 25. http://www.sxc.hu/photo/314594
  26. 26. Typical patch script 23
  27. 27. Typical patch script update.sh 24
  28. 28. http://www.sxc.hu/photo/1196126
  29. 29. Branches Merge problems 26
  30. 30. Branches Trunk patch-001.sql patch-002.sql patch-003.sql 27
  31. 31. Branches Trunk patch-001.sql patch-002.sql patch-003.sql Branch A create branch patch-004.sql patch-004.sql patch-005.sql patch-005.sql Merge 28
  32. 32. Branches Trunk patch-001.sql patch-002.sql patch-003.sql Branch A create branch patch-004.sql patch-006.sql patch-004.sql patch-005.sql patch-007.sql patch-005.sql Merge 28
  33. 33. Branches Trunk patch-001.sql Branch A create branch patch-002.sql patch-002.sql patch-003.sql Branch B create branch patch-003.sql Merge patch-004.sql patch-004.sql patch-004.sql patch-005.sql patch-005.sql Merge patch-005.sql Merge Merge 29
  34. 34. Separate sequence db/patches/trunk/ db/patches/branchA/ patch-001.sql patch-001.sql patch-002.sql patch-002.sql patch-003.sql 30
  35. 35. Separate sequence db/patches/trunk/ db/patches/branchA/ patch-001.sql patch-001.sql patch-002.sql patch-002.sql patch-003.sql Trunk version 3 BranchA version 2 30
  36. 36. Patchfile naming patch_20100611_1430.sql 31
  37. 37. Patch log 32
  38. 38. http://www.sxc.hu/photo/692740
  39. 39. Phing & DB Deploy Avoiding the NIH syndrome 34
  40. 40. http://phing.info/ 35
  41. 41. Phing 36
  42. 42. 37
  43. 43. DB Deploy 38
  44. 44. DB Deploy db/patches/1-create_user_table.sql 39
  45. 45. Phing & DB Deploy 40
  46. 46. DB Deploy changelog table: 41
  47. 47. DB Deploy changelog table: 41
  48. 48. DB Deploy PHP 42
  49. 49. DB Deploy SQL 43
  50. 50. DB Deploy Features 44
  51. 51. Liquibase A different approach 45
  52. 52. Liquibase www.liquibase.org 46
  53. 53. Liquibase 47
  54. 54. Liquibase 48
  55. 55. Liquibase 49
  56. 56. Liquibase Updating Reverting Tagging Generate XML Diff 50
  57. 57. http://www.sxc.hu/photo/1241520
  58. 58. Liquibase Branches 52
  59. 59. Liquibase DBMS Support 53
  60. 60. Liquibase Documentation 54
  61. 61. Liquibase Java 55
  62. 62. Akrabat DB Schema Manager Zend Framework specific solution 56
  63. 63. Akrabat DB Schema Manager Zend Framework Proposed by Rob Allen in 2006 Recently implemented Might be in ZF in the near future http://github.com/akrabat/Akrabat 57
  64. 64. Writing the patch scripts/migrations/001-CreateUserTable.php 58
  65. 65. Writing the patch scripts/migrations/001-CreateUserTable.php 59
  66. 66. Akrabat DB Schema Manager PHP Patches 60
  67. 67. Akrabat DB Schema Manager Easy syntax if you know ZF 61
  68. 68. Akrabat DB Schema Manager Easy to use 62
  69. 69. Akrabat DB Schema Manager Branch merging 63
  70. 70. Doctrine Migrations 64
  71. 71. Doctrine Migrations http://www.doctrine-project.org/ 65
  72. 72. Doctrine Migrations 66
  73. 73. Doctrine Migrations Update-to-version 67
  74. 74. Doctrine Migrations Generate patches 68
  75. 75. Doctrine Migrations Useful if you’re already using Doctrine ORM 69
  76. 76. Summary 70
  77. 77. Summary Patchfiles Akrabat DB Schema Manager http://akrabat.com • Automating http://github.com/akrabat/Akrabat • Branch merging Doctrine Migrations Phing + DB Deploy http://www.doctrine-project.org http://phing.info http://dbdeploy.com Liquibase http://www.liquibase.org 71
  78. 78. Questions ? 72
  79. 79. Contact me Harrie Verveer Software Engineer at Ibuildings E-mail: harrie@ibuildings.nl Skype: harrie-ibuildings Twitter: @harrieverveer http://joind.in/1544 73
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×