South talk
Upcoming SlideShare
Loading in...5
×
 

South talk

on

  • 716 views

 

Statistics

Views

Total Views
716
Views on SlideShare
714
Embed Views
2

Actions

Likes
3
Downloads
8
Comments
0

1 Embed 2

https://twitter.com 2

Accessibility

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

South talk South talk Presentation Transcript

  • Schema Migrations for Django Friday, September 27, 13
  • WHAT WE’LL COVER How to use South • South and git • Data migrations • Model inheritance •Wacky Stuff Friday, September 27, 13
  • 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
  • SETTING UP south.readthedocs.org Friday, September 27, 13
  • SETTING UP OR pip install south 1. Install Friday, September 27, 13
  • SETTING UP 2. Installed apps Friday, September 27, 13
  • SETTING UP 3. syncdb Friday, September 27, 13
  • SETTING UP (Create an app & models) Friday, September 27, 13
  • SETTING UP Existing apps: convert_to_south appname New apps: schemamigration appname --initial 4. Setup each app Friday, September 27, 13
  • HOW IT WORKS • Migrations folder • South migrations history table • Models.py • Database schema & data Creates: Reads from: Alters: Friday, September 27, 13
  • HOW IT WORKS Friday, September 27, 13
  • HOW IT WORKS Friday, September 27, 13
  • HOW IT WORKS Friday, September 27, 13
  • 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
  • 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
  • AVOIDING GITTROUBLES Friday, September 27, 13
  • 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
  • AVOIDING GITTROUBLES Resolving: NEVER delete a migration that has others have access to Friday, September 27, 13
  • 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
  • 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
  • AVOIDING GITTROUBLES BETTER: git feng shui models, migrations other code other code previous commit FEATURE DEVELOPMENT models, migrations Friday, September 27, 13
  • DATA MIGRATIONS Move date_of_birth from Authors to UserProfile Friday, September 27, 13
  • DATA MIGRATIONS SANDWICH schemamigration datamigration schemamigration Friday, September 27, 13
  • DATA MIGRATIONS BOTTOM SLICE: schemamigration Friday, September 27, 13
  • DATA MIGRATIONS MIDDLE: datamigration Friday, September 27, 13
  • DATA MIGRATIONS MIDDLE: datamigration Friday, September 27, 13
  • DATA MIGRATIONS MIDDLE: datamigration Friday, September 27, 13
  • DATA MIGRATIONS TOP SLICE: schemamigration Remove date_of_birth from Author Friday, September 27, 13
  • DATA MIGRATIONS TOP SLICE: schemamigration Remove date_of_birth from Author Remember: Data migration needs all information available. Friday, September 27, 13
  • MODEL INHERITANCE Friday, September 27, 13
  • MODEL INHERITANCE Friday, September 27, 13
  • MODEL INHERITANCE Friday, September 27, 13
  • MODEL INHERITANCE Friday, September 27, 13
  • WACKY STUFF Friday, September 27, 13
  • TESTING Friday, September 27, 13