South talk

835 views

Published on

Published in: News & Politics, Business
  • Be the first to comment

South talk

  1. 1. Schema Migrations for Django Friday, September 27, 13
  2. 2. WHAT WE’LL COVER How to use South • South and git • Data migrations • Model inheritance •Wacky Stuff Friday, September 27, 13
  3. 3. WHY SOUTH? Generally: • Migrations allow you to synchronize your database with your code. • Important for: • multiple developers • rolling back • migrating data • deploying Specifically: • South is the standard • South is being rolled into Django in 1.7 • South is awesome & fun! Friday, September 27, 13
  4. 4. SETTING UP south.readthedocs.org Friday, September 27, 13
  5. 5. SETTING UP OR pip install south 1. Install Friday, September 27, 13
  6. 6. SETTING UP 2. Installed apps Friday, September 27, 13
  7. 7. SETTING UP 3. syncdb Friday, September 27, 13
  8. 8. SETTING UP (Create an app & models) Friday, September 27, 13
  9. 9. SETTING UP Existing apps: convert_to_south appname New apps: schemamigration appname --initial 4. Setup each app Friday, September 27, 13
  10. 10. HOW IT WORKS • Migrations folder • South migrations history table • Models.py • Database schema & data Creates: Reads from: Alters: Friday, September 27, 13
  11. 11. HOW IT WORKS Friday, September 27, 13
  12. 12. HOW IT WORKS Friday, September 27, 13
  13. 13. HOW IT WORKS Friday, September 27, 13
  14. 14. NORMAL WORKFLOW update model manage.py schemamigration appname --auto manage.py migrate (appname) eureka! a better model... manage.py migrate backwards (zero) update model manage.py migrate --list delete files*** redo the schemamigration manage.py schemamigration appname --auto { Friday, September 27, 13
  15. 15. NORMAL WORKFLOW update model manage.py schemamigration appname --auto manage.py migrate (appname) eureka! a better model... manage.py migrate backwards (zero) update model manage.py migrate --list delete files*** redo the schemamigration manage.py schemamigration appname --auto { DANGER! Friday, September 27, 13
  16. 16. AVOIDING GITTROUBLES Friday, September 27, 13
  17. 17. AVOIDING GITTROUBLES • update Authors model • schemamigration: 0002 • eureka! • migrates back to 0001 • deletes migration 0002 • creates new 0002 • writes code • pulls code • migrates to 0002 • writes code • pulls code • ghost migration Dev #1:Author Dev #2: Blog Friday, September 27, 13
  18. 18. AVOIDING GITTROUBLES Resolving: NEVER delete a migration that has others have access to Friday, September 27, 13
  19. 19. AVOIDING GITTROUBLES • update Authors model • schemamigration: 0002 • updates Blog model • schemamigration: 0003 • pushes Dev #1:Author Dev #2: Blog • update Blog model • schemamigration: 0002 • updates Blog model • schemamigration: 0003 • pulls Friday, September 27, 13
  20. 20. AVOIDING GITTROUBLES • update Authors model • schemamigration: 0002 • updates Blog model • schemamigration: 0003 • pushes Dev #1:Author Dev #2: Blog • update Blog model • schemamigration: 0002 • updates Blog model • schemamigration: 0003 • pulls = CONFLICT Friday, September 27, 13
  21. 21. AVOIDING GITTROUBLES BETTER: git feng shui models, migrations other code other code previous commit FEATURE DEVELOPMENT models, migrations Friday, September 27, 13
  22. 22. DATA MIGRATIONS Move date_of_birth from Authors to UserProfile Friday, September 27, 13
  23. 23. DATA MIGRATIONS SANDWICH schemamigration datamigration schemamigration Friday, September 27, 13
  24. 24. DATA MIGRATIONS BOTTOM SLICE: schemamigration Friday, September 27, 13
  25. 25. DATA MIGRATIONS MIDDLE: datamigration Friday, September 27, 13
  26. 26. DATA MIGRATIONS MIDDLE: datamigration Friday, September 27, 13
  27. 27. DATA MIGRATIONS MIDDLE: datamigration Friday, September 27, 13
  28. 28. DATA MIGRATIONS TOP SLICE: schemamigration Remove date_of_birth from Author Friday, September 27, 13
  29. 29. DATA MIGRATIONS TOP SLICE: schemamigration Remove date_of_birth from Author Remember: Data migration needs all information available. Friday, September 27, 13
  30. 30. MODEL INHERITANCE Friday, September 27, 13
  31. 31. MODEL INHERITANCE Friday, September 27, 13
  32. 32. MODEL INHERITANCE Friday, September 27, 13
  33. 33. MODEL INHERITANCE Friday, September 27, 13
  34. 34. WACKY STUFF Friday, September 27, 13
  35. 35. TESTING Friday, September 27, 13

×