Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Database version control - pf congres version

2,121 views

Published on

Slides as used for my database version control talk at PF Congres. I removed the photo's because I wasn't exactly sure if the licenses the photo's were published under allowed me to redistribute them in this slide show. I left the references to the original images in.

  • Be the first to comment

Database version control - pf congres version

  1. 1. Database Version Control Without Pain Harrie Verveer PFCongres - April 17th 2010
  2. 2. Database Version Control What’s the problem? 2
  3. 3. Here used to be an image of an airplane that I removed because of the license the image was published under http://www.sxc.hu/photo/754535
  4. 4. Here used to be an image of an airplane that I removed because of the license the image was published under http://www.sxc.hu/photo/1207911
  5. 5. http://en.wikipedia.org/wiki/File:STS120LaunchHiRes.jpg Here used to be an image of the space shuttle that I removed because of the license the image was published under
  6. 6. http://www.sxc.hu/photo/1255121 Here used to be an image of a bike that I removed because of the license the image was published under
  7. 7. Why Database Version Control 7
  8. 8. Why Database Version Control Database Version Control is left behind 8
  9. 9. Simple Patching Strategy The basic idea 9
  10. 10. Simple patching strategy Patch files 10
  11. 11. Simple patching strategy 11
  12. 12. Simple patching strategy Mostly structural changes 12
  13. 13. Simple patching strategy Chronological filenames 13
  14. 14. Simple patching strategy Remember last executed patch 14
  15. 15. Simple patching strategy Development Write code Write DB patches Apply patches to own DB Apply patches Commit Update 15
  16. 16. Example patch file patch-001.sql 16
  17. 17. Fixing patches patch-002.sql 17
  18. 18. Fixing patches patch-002.sql 17
  19. 19. Fixing patches patch-002.sql 17
  20. 20. Fixing patches patch-003.sql 18
  21. 21. Fixing patches patch-003.sql Never modify a patch file once it’s under version control 18
  22. 22. Undo patch files patch-001.sql 19
  23. 23. Undo patch files undo-001.sql 20
  24. 24. Here used to be an image of a one-way sign that I removed because of the license the image was published under http://www.freefoto.com/preview/41-07-7
  25. 25. Process Copy production to test environment Apply patches Run tests Backup live database Update production 22
  26. 26. Bonus points Install.sql 23
  27. 27. Bonus points Initial dummy content 24
  28. 28. Here used to be an image of a guy in a rowing boat that I removed because of the license the image was published under http://www.sxc.hu/photo/643214
  29. 29. Here used to be an image of a sunken boat that I removed because of the license the image was published under http://www.sxc.hu/photo/946855
  30. 30. Automating the process Faster & Safer 27
  31. 31. Typical patch script Run the patches 28
  32. 32. Typical patch script Keep track of last executed patch 29
  33. 33. Typical patch script 30
  34. 34. Typical patch script 31
  35. 35. Typical patch script 32
  36. 36. Typical patch script update.sh 33
  37. 37. Branches Merge problems 34
  38. 38. Branches Trunk patch-001.sql patch-002.sql patch-003.sql 35
  39. 39. 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 36
  40. 40. 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 37
  41. 41. 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 37
  42. 42. 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 38
  43. 43. Separate sequence db/patches/trunk/ db/patches/branchA/ patch-001.sql patch-001.sql patch-002.sql patch-002.sql patch-003.sql 39
  44. 44. 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 39
  45. 45. Patchfile naming Filenames based on time 40
  46. 46. Patch log At this point our patch number tracking doesn’t work anymore!!! patch_20100322_2158.sql patch_20100323_0839.sql patch_20100327_1025.sql 41
  47. 47. Patch log At this point our patch number tracking doesn’t work anymore!!! patch_20100322_2158.sql patch_20100323_0839.sql patch_20100327_1025.sql Last executed: patch_20100327_1025 41
  48. 48. Patch log At this point our patch number tracking doesn’t work anymore!!! patch_20100322_2158.sql patch_20100322_2253.sql patch_20100323_0839.sql patch_20100325_1528.sql patch_20100327_1025.sql patch_20100328_1230.sql Last executed: patch_20100327_1025 41
  49. 49. Patch log At this point our patch number tracking doesn’t work anymore!!! patch_20100322_2158.sql patch_20100322_2253.sql patch_20100323_0839.sql patch_20100325_1528.sql patch_20100327_1025.sql patch_20100328_1230.sql Last executed: patch_20100327_1025 41
  50. 50. Patch log At this point our patch number tracking doesn’t work anymore!!! patch_20100322_2158.sql patch_20100322_2253.sql patch_20100323_0839.sql patch_20100325_1528.sql patch_20100327_1025.sql patch_20100328_1230.sql patch_20100322_2158.sql patch_20100322_2253.sql Last executed: patch_20100323_0839.sql patch_20100327_1025 patch_20100325_1528.sql patch_20100327_1025.sql patch_20100328_1230.sql 41
  51. 51. Patch log At this point our patch number tracking doesn’t work anymore!!! patch_20100322_2158.sql patch_20100322_2253.sql patch_20100323_0839.sql patch_20100325_1528.sql patch_20100327_1025.sql patch_20100328_1230.sql patch_20100322_2158.sql patch_20100322_2253.sql Last executed: patch_20100323_0839.sql patch_20100327_1025 patch_20100325_1528.sql patch_20100327_1025.sql patch_20100328_1230.sql 41
  52. 52. Patch log 42
  53. 53. Branches False sense of security 43
  54. 54. Phing Avoiding the NIH syndrome 44
  55. 55. http://phing.info/ 45
  56. 56. Phing 46
  57. 57. 47
  58. 58. DB Deploy 48
  59. 59. DB Deploy 49
  60. 60. DB Deploy 49
  61. 61. DB Deploy changelog table: 50
  62. 62. DB Deploy changelog table: 50
  63. 63. Akrabat DB Schema Manager Zend Framework specific solution 51
  64. 64. 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 52
  65. 65. Writing the patch scripts/migrations/001-CreateUserTable.php 53
  66. 66. Writing the patch scripts/migrations/001-CreateUserTable.php 54
  67. 67. Running the patch 55
  68. 68. Running the patch 55
  69. 69. Running the patch 56
  70. 70. Running the patch 57
  71. 71. Akrabat DB Schema Manager Easy to use if you know ZF PHP instead of SQL-only Easy to ‘undo’ patches Branch merging problem Run from your deploy script 58
  72. 72. Multiple servers ssh harrie@webserver188 59
  73. 73. http://www.capify.org/ 60
  74. 74. Capistrano cd /dir/where/my/app/is svn update php updatedb.php 61
  75. 75. Capistrano cd /dir/where/my/app/is svn update php updatedb.php 62
  76. 76. Capistrano & the database 63
  77. 77. Capistrano Automate deployment No coding needed Extending possible Useful tool for PHP developers Replace railsy voodoo with PHPish 1337ness 64
  78. 78. Summary 65
  79. 79. Summary Patchfiles • Automating • Branch merging Phing + DB Deploy http://phing.info http://dbdeploy.com Akrabat DB Schema Manager http://akrabat.com http://github.com/akrabat/Akrabat Capistrano http://capify.org 66
  80. 80. Questions ? 67
  81. 81. Contact me Harrie Verveer Software Engineer at Ibuildings E-mail: harrie@ibuildings.nl Skype: harrie-ibuildings Twitter: @harrieverveer http://joind.in/1499 68
  82. 82. Dutch PHP Conference june 10 - 12 RAI Amsterdam http://phpconference.nl 69

×