Keeping Your Database and PHP in Sync
Upcoming SlideShare
Loading in...5
×
 

Keeping Your Database and PHP in Sync

on

  • 3,504 views

 

Statistics

Views

Total Views
3,504
Views on SlideShare
3,495
Embed Views
9

Actions

Likes
2
Downloads
21
Comments
0

2 Embeds 9

http://www.slideshare.net 5
http://developer.tradekey.pk 4

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

     Keeping Your Database and PHP in Sync Keeping Your Database and PHP in Sync Presentation Transcript

    • KEEPING YOUR DATABASE AND PHP IN SYNC MAGGIE NELSON MAY 22, 2008
    • dev prod
    • dev prod
    • dev qa prod
    • dev qa staging prod
    • dev1 (new stuff) dev2 qa1 staging prod (new stuff) (new stuff) dev3 qa2 (maintenance) (maintenance)
    • new stuff trunk maintenance 1.0 2.0 3.0
    • PHP and DB are separate
    • = + PHP = + PHP
    • releaseNumber.sql
    • release 2.0 + PHP cut 2.0 release at run release.2.0.sql install 2.0 code svn revision 207 in database
    • reverting release 2.0 + PHP revert to previous ??? version of code (prior to in database svn revision 207)
    • new stuff r203 r207 r415 trunk 1-203 204-207 208-415 maintenance 1.0 2.0 3.0
    • releaseNumber.undo.sql
    • 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)
    • Frequent database changes during release cycle
    • 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
    • releaseNumber.sql
    • releaseNumber.sql
    • Communication between developers
    • dev1 (new stuff) dev2 qa1 staging prod (new stuff) (new stuff) dev3 qa2 (maintenance) (maintenance)
    • 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
    • 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
    • releaseNumber.sql
    • DB deltas
    • DB deltas as XML
    • 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
    • Stored procedures
    • Calling stored procedures from PHP
    • Oracle example - pkg header
    • Oracle example - pkg body
    • 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
    • Stored procedures in deltas
    • Reference, don’t copy
    • svn cat -r[some_revision] Friend/pkg.sql >> runThis.sql svn cat -r[some_revision] Friend/pkg_body.sql >> runThis.sql [some_revision] ??
    • 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
    • svn log -r PREV:HEAD delta7.sql ------------------------------------------------------------------------ r107 | maggie_n | 2008-02-25 15:13:50 -0500 (Mon, 25 Feb 2008) | 15 lines
    • 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’];
    • Automagically...
    • Communication between development branches
    • dev1 (new stuff) dev2 qa1 staging prod (new stuff) (new stuff) dev3 qa2 (maintenance) (maintenance)
    • new stuff trunk maintenance 1.0 2.0 3.0 svn:external deltas
    • svn:externals http://svn.example.com/svn/myapp/ trunk branch/ new_stuff/ 1.0/ 2.0/ 3.0/ deltas/
    • 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
    • new stuff trunk maintenance 1.0 2.0 3.0 svn:external deltas deltas 1-...
    • 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
    • new stuff trunk maintenance 1.0 2.0 3.0
    • Summary PHP + DB + XML + svn = awesome!
    • Questions?
    • Thanks! more info: maggienelson.com