Slide 1

Slide 1 text

south Andrew�Godwin Migrating�with [email protected]

Slide 2

Slide 2 text

One�of�many south Migrating�with django-evolution migratory dmigrations deseb

Slide 3

Slide 3 text

Two�parts south Migrating�with migration�engine database�abstractor MySQL PostgreSQL SQLite SQL�Server tracking dependencies conflicts

Slide 4

Slide 4 text

What�are�migrations? south Migrating�with /�mutations�/�diffs�/�etc

Slide 5

Slide 5 text

Problem:�database�schema�isn't meaningfully�versioned south Migrating�with -�It's�usually�in�a�VCS�(models.py),�but�the ��database�exists��outside�of�version�control. -�Migration�libraries�essentially�add�version�control ��to�database�schemas.

Slide 6

Slide 6 text

South�keeps�its�distance�from�models.py. south Migrating�with You're�never�sure�if�it's�from�the�past,�present�or�future. (see:�cheesy�time-travel�films)

Slide 7

Slide 7 text

You�can�use�it,�though. south Migrating�with While�migrations�are�independent�from�it,�they�can be�made�from�models.py�automatically.

Slide 8

Slide 8 text

A�migration! south Migrating�with from south.db import db from core.models import * cl ass Migration: def forwards(self): db.add_column("core_nation", "slug", models.SlugField(unique=True, default="test") ) def backwards(self): db.add_column("core_nation", "slug")

Slide 9

Slide 9 text

How�is�migration�formed? south Migrating�with ./manage.py startmigration core test_migration The�South�command App�name Migration�name ./manage.py startmigration core \ test_migration Blank�migration: Add�everything�(initial;�replaces�the�syncdb): --initial ./manage.py startmigration core \ test_migration Add�a�new�field: --add-field Picture.slug These�all�make�a�file�like�c ore/migrations/0002_test_migration.py.

Slide 10

Slide 10 text

Migrations�are�per-app. south Migrating�with If�an�app�doesn't�need�migrations,�it�uses�syncdb�as�normal. If�apps�depend�on�others,�there's�a�dependency�resolver.

Slide 11

Slide 11 text

Installation south Migrating�with Put�South�somewhere�on�the�Python�path svn co http://.../trun k/south/ easy_install South or Add�it�to�INSTALLED_APPS INSTALLED_APPS = [ ... , "south" ] Run�syncdb�(South�uses�a�table�to�track�applied�migrations) ./manage.py syncdb That's�it.�Start�migrating. (We�have�docs�on�things�like�converting�existing�apps)

Slide 12

Slide 12 text

Database�Abstraction south Migrating�with Sigh.

Slide 13

Slide 13 text

south Migrating�with epic�fail fail win M ySQL Postgres SQLite SQL�Server Highly�scientific�graph No�DDL�Transactions No�Column�Alters Awesome. Ugh.

Slide 14

Slide 14 text

south Migrating�with We�have�good�support�for�PostgreSQL�and�MySQL But�MySQL�users�can't�wrap�migrations�in�transactions. We�have�alright�support�for�SQLite Haven't�got�the�alter_column�workarounds�in�yet. We�have�basic�support�for�SQL�Server It�wasn't�me,�honest.

Slide 15

Slide 15 text

south Migrating�with # M ock M odel s User = db.mock_model(model_name='User', db_table='auth_user', db_tablespace='', pk_field_name='id', pk_field_type=models.AutoField) # M odel ' User Pr of i l e' db.create_table('core_userprofile', ( ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)), ('user', models.OneToOneField(User, related_name="profile")), )) API�Example

Slide 16

Slide 16 text

south Migrating�with The�Future ORM�in�migrations More�databases Robust�models.py�parsing

Slide 17

Slide 17 text

south Migrating�with Fin. http://south.aeracode.org Ideas,�tickets�and�patches�always�welcome Andrew�Godwin [email protected]