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.

Keeping Your Database and PHP in Sync

3,674 views

Published on

Published in: Technology
  • Be the first to comment

Keeping Your Database and PHP in Sync

  1. 1. KEEPING YOUR DATABASE AND PHP IN SYNC MAGGIE NELSON MAY 22, 2008
  2. 2. dev prod
  3. 3. dev prod
  4. 4. dev qa prod
  5. 5. dev qa staging prod
  6. 6. dev1 (new stuff) dev2 qa1 staging prod (new stuff) (new stuff) dev3 qa2 (maintenance) (maintenance)
  7. 7. new stuff trunk maintenance 1.0 2.0 3.0
  8. 8. PHP and DB are separate
  9. 9. = + PHP = + PHP
  10. 10. releaseNumber.sql
  11. 11. release 2.0 + PHP cut 2.0 release at run release.2.0.sql install 2.0 code svn revision 207 in database
  12. 12. reverting release 2.0 + PHP revert to previous ??? version of code (prior to in database svn revision 207)
  13. 13. new stuff r203 r207 r415 trunk 1-203 204-207 208-415 maintenance 1.0 2.0 3.0
  14. 14. releaseNumber.undo.sql
  15. 15. reverting release 2.0 + PHP revert to previous run release.2.0.undo.sql ??? version of code (prior to in database in database svn revision 207)
  16. 16. Frequent database changes during release cycle
  17. 17. Frequent changes from dev -> QA dev qa staging prod run statements from update QA with figure out last update release.2.0.0.sql since freshest PHP code ran from release.2.0.sql last DB updates
  18. 18. releaseNumber.sql
  19. 19. releaseNumber.sql
  20. 20. Communication between developers
  21. 21. dev1 (new stuff) dev2 qa1 staging prod (new stuff) (new stuff) dev3 qa2 (maintenance) (maintenance)
  22. 22. devs making DB changes dev1 dev2 run statements from update devX with figure out last update release.2.0.0.sql since freshest PHP code ran from release.2.0.sql last DB updates
  23. 23. dev1 writes new code database YES dev1 sends e-mail to dev2 with dev1 commits code changes? instructions for the DB change NO dev2 NO dev2: svn up to get checks dev2: svn up new code email? YES dev2 reads instructions dev2 dev2 has new YES follows NO dev2 environment is instructions code correctly? broken EPIC FAIL
  24. 24. releaseNumber.sql
  25. 25. DB deltas
  26. 26. DB deltas as XML
  27. 27. dev1 writes new code database YES encapsulate DB changes? change in a delta NO dev1 commits code dev2: svn up to get run script to check for new YES run script to parse and new code new deltas deltas? apply new deltas NO dev2 has new code
  28. 28. Stored procedures
  29. 29. Calling stored procedures from PHP
  30. 30. Oracle example - pkg header
  31. 31. Oracle example - pkg body
  32. 32. friend_pkg db/Friend/pkg.sql (header) friend_pkg db/Friend/pkg_body.sql (body) models models/FriendModel.php views views/addFriend.phtml controllers/ controllers FriendController.php
  33. 33. Stored procedures in deltas
  34. 34. Reference, don’t copy
  35. 35. svn cat -r[some_revision] Friend/pkg.sql >> runThis.sql svn cat -r[some_revision] Friend/pkg_body.sql >> runThis.sql [some_revision] ??
  36. 36. encapsulate DB changes (DDL + DML) in a delta (e.g. delta7.xml) make stored procedure changes reference stored procedure changes in the delta make PHP changes commit PHP changes, stored procedure changes and the new delta7.xml
  37. 37. svn log -r PREV:HEAD delta7.sql ------------------------------------------------------------------------ r107 | maggie_n | 2008-02-25 15:13:50 -0500 (Mon, 25 Feb 2008) | 15 lines
  38. 38. svn log -r PREV:HEAD delta7.sql --xml <?xml version=quot;1.0quot;?> <log> <logentry revision=quot;107quot;> <author>maggie_n</author> <date>2008-02-25T20:13:50.097229Z</date> <msg>My awesome delta number 7.</msg></logentry> </log> $deltaSvnRevision = $myXml->logentry[0][‘revision’];
  39. 39. Automagically...
  40. 40. Communication between development branches
  41. 41. dev1 (new stuff) dev2 qa1 staging prod (new stuff) (new stuff) dev3 qa2 (maintenance) (maintenance)
  42. 42. new stuff trunk maintenance 1.0 2.0 3.0 svn:external deltas
  43. 43. svn:externals http://svn.example.com/svn/myapp/ trunk branch/ new_stuff/ 1.0/ 2.0/ 3.0/ deltas/
  44. 44. create new deltas directory parallel to trunk and branches in trunk or branch you’re working in: svn propedit svn:externals . edit file that opens, add: deltas http://svn.example.com/myapp/deltas save and exit svn up svn commit
  45. 45. new stuff trunk maintenance 1.0 2.0 3.0 svn:external deltas deltas 1-...
  46. 46. central file to associate delta 2 branch/trunk trunk: branches/1.0 - delta1 - delta1 - delta2 branches/2.0 branches/new_stuff - delta1 - delta3 - delta2 - delta4 branches/3.0 - delta1 - delta2 - delta3 - delta4
  47. 47. new stuff trunk maintenance 1.0 2.0 3.0
  48. 48. Summary PHP + DB + XML + svn = awesome!
  49. 49. Questions?
  50. 50. Thanks! more info: maggienelson.com

×