keeping your database and php in sync

55
MAY 22, 2008 MAGGIE NELSON KEEPING YOUR DATABASE AND PHP IN SYNC

Upload: azghanvi

Post on 15-Jan-2015

3.316 views

Category:

Technology


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Keeping Your Database and PHP in Sync

MAY 22, 2008MAGGIE NELSON

KEEPING YOUR DATABASE AND PHP IN SYNC

Page 2: Keeping Your Database and PHP in Sync

dev prod

Page 3: Keeping Your Database and PHP in Sync

dev prod

Page 4: Keeping Your Database and PHP in Sync

dev prodqa

Page 5: Keeping Your Database and PHP in Sync

dev prodstagingqa

Page 6: Keeping Your Database and PHP in Sync

dev2 prodstagingqa1

dev1

dev3 qa2(maintenance) (maintenance)

(new stuff)

(new stuff) (new stuff)

Page 7: Keeping Your Database and PHP in Sync

new stuff

trunk

1.0 2.0 3.0maintenance

Page 8: Keeping Your Database and PHP in Sync

PHP and DB are separate

Page 9: Keeping Your Database and PHP in Sync

= +

= +

PHP

PHP

Page 10: Keeping Your Database and PHP in Sync

releaseNumber.sql

Page 11: Keeping Your Database and PHP in Sync

+

PHP

cut 2.0 release at svn revision 207

run release.2.0.sql in database

install 2.0 code

release 2.0

Page 12: Keeping Your Database and PHP in Sync

+

PHP

revert to previous version of code (prior to

svn revision 207)

??? in database

reverting release 2.0

Page 13: Keeping Your Database and PHP in Sync

new stuff

trunk

1.0 2.0 3.0maintenance

r207r203 r415

1-203 204-207 208-415

Page 14: Keeping Your Database and PHP in Sync

releaseNumber.undo.sql

Page 15: Keeping Your Database and PHP in Sync

+

PHP

revert to previous version of code (prior to

svn revision 207)

??? in database

reverting release 2.0

run release.2.0.undo.sql in database

Page 16: Keeping Your Database and PHP in Sync

Frequent database changes duringrelease cycle

Page 17: Keeping Your Database and PHP in Sync

dev prodstagingqa

Frequent changes from dev -> QA

update QA with freshest PHP code

figure out last update ran from release.2.0.sql

run statements from release.2.0.0.sql since

last DB updates

Page 18: Keeping Your Database and PHP in Sync

releaseNumber.sql

Page 19: Keeping Your Database and PHP in Sync

releaseNumber.sql

Page 20: Keeping Your Database and PHP in Sync

Communication between developers

Page 21: Keeping Your Database and PHP in Sync

dev2 prodstagingqa1

dev1

dev3 qa2(maintenance) (maintenance)

(new stuff)

(new stuff) (new stuff)

Page 22: Keeping Your Database and PHP in Sync

dev1 dev2

update devX with freshest PHP code

figure out last update ran from release.2.0.sql

run statements from release.2.0.0.sql since

last DB updates

devs making DB changes

Page 23: Keeping Your Database and PHP in Sync

dev1 writes new code

dev1 commits code

dev2: svn up to get new code

dev2 has new code

dev1 sends e-mail to dev2 with instructions for the DB change

dev2 reads instructions

dev2: svn up

dev2 environment is broken

database changes?

dev2 checks email?

dev2 follows

instructions correctly?

EPIC FAIL

YES

YES

YES

NO

NO

NO

Page 24: Keeping Your Database and PHP in Sync

releaseNumber.sql

Page 25: Keeping Your Database and PHP in Sync

DB deltas

Page 26: Keeping Your Database and PHP in Sync

DB deltas as XML

Page 27: Keeping Your Database and PHP in Sync

dev1 writes new code

dev1 commits code

database changes?

YES encapsulate DB change in a delta

NO

dev2: svn up to get new code

run script to check for new deltas

dev2 has new code

new deltas?

run script to parse and apply new deltas

YES

NO

Page 28: Keeping Your Database and PHP in Sync

Stored procedures

Page 29: Keeping Your Database and PHP in Sync

Calling stored procedures from PHP

Page 30: Keeping Your Database and PHP in Sync

Oracle example - pkg header

Page 31: Keeping Your Database and PHP in Sync

Oracle example - pkg body

Page 32: Keeping Your Database and PHP in Sync

friend_pkg(header)

friend_pkg(body)

models

views

db/Friend/pkg.sql

db/Friend/pkg_body.sql

models/FriendModel.php

views/addFriend.phtml

controllers controllers/FriendController.php

Page 33: Keeping Your Database and PHP in Sync

Stored procedures in deltas

Page 34: Keeping Your Database and PHP in Sync

Reference, don’t copy

Page 35: Keeping Your Database and PHP in Sync

svn cat -r[some_revision] Friend/pkg.sql >> runThis.sql

svn cat -r[some_revision] Friend/pkg_body.sql >> runThis.sql

[some_revision] ??

Page 36: Keeping Your Database and PHP in Sync

encapsulate DB changes (DDL + DML) in a delta (e.g. delta7.xml)

make stored procedure changes

make PHP changes

reference stored procedure changes in the delta

commit PHP changes, stored procedure changes and the new delta7.xml

Page 37: Keeping Your Database and PHP in Sync

------------------------------------------------------------------------r107 | maggie_n | 2008-02-25 15:13:50 -0500 (Mon, 25 Feb 2008) | 15 lines

svn log -r PREV:HEAD delta7.sql

Page 38: Keeping Your Database and PHP in Sync

<?xml version="1.0"?><log><logentry revision="107"><author>maggie_n</author><date>2008-02-25T20:13:50.097229Z</date><msg>My awesome delta number 7.</msg></logentry></log>

svn log -r PREV:HEAD delta7.sql --xml

$deltaSvnRevision = $myXml->logentry[0][‘revision’];

Page 39: Keeping Your Database and PHP in Sync

Automagically...

Page 40: Keeping Your Database and PHP in Sync
Page 41: Keeping Your Database and PHP in Sync
Page 42: Keeping Your Database and PHP in Sync
Page 43: Keeping Your Database and PHP in Sync
Page 44: Keeping Your Database and PHP in Sync
Page 45: Keeping Your Database and PHP in Sync

Communication between development branches

Page 46: Keeping Your Database and PHP in Sync

dev2 prodstagingqa1

dev1

dev3 qa2(maintenance) (maintenance)

(new stuff)

(new stuff) (new stuff)

Page 47: Keeping Your Database and PHP in Sync

new stuff

trunk

1.0 2.0 3.0maintenance

deltassvn:external

Page 48: Keeping Your Database and PHP in Sync

http://svn.example.com/svn/myapp/ trunk branch/ new_stuff/ 1.0/ 2.0/ 3.0/ deltas/

svn:externals

Page 49: Keeping Your Database and PHP in Sync

create new deltas directory parallel to trunk and branches

in trunk or branch you’re working in:svn propedit svn:externals .

save and exit

edit file that opens, add:deltas http://svn.example.com/myapp/deltas

svn upsvn commit

Page 50: Keeping Your Database and PHP in Sync

new stuff

trunk

1.0 2.0 3.0maintenance

deltassvn:external

deltas 1-...

Page 51: Keeping Your Database and PHP in Sync

central file to associate delta 2 branch/trunk

trunk:- delta1- delta2

branches/new_stuff- delta3- delta4

branches/1.0- delta1

branches/2.0- delta1- delta2

branches/3.0- delta1- delta2- delta3- delta4

Page 52: Keeping Your Database and PHP in Sync

new stuff

trunk

1.0 2.0 3.0maintenance

Page 53: Keeping Your Database and PHP in Sync

Summary

PHP DB XML+ + = awesome!svn+

Page 54: Keeping Your Database and PHP in Sync

Questions?

Page 55: Keeping Your Database and PHP in Sync

Thanks!

more info: maggienelson.com