Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Models and Migrations and Schemas - oh my!
Search
Andrew Godwin
September 06, 2012
Programming
5
2k
Models and Migrations and Schemas - oh my!
A talk from DjangoCon US 2012 on South, Django, and schema migrations.
Andrew Godwin
September 06, 2012
Tweet
Share
More Decks by Andrew Godwin
See All by Andrew Godwin
Reconciling Everything
andrewgodwin
1
250
Django Through The Years
andrewgodwin
0
150
Writing Maintainable Software At Scale
andrewgodwin
0
380
A Newcomer's Guide To Airflow's Architecture
andrewgodwin
0
300
Async, Python, and the Future
andrewgodwin
2
590
How To Break Django: With Async
andrewgodwin
1
650
Taking Django's ORM Async
andrewgodwin
0
660
The Long Road To Asynchrony
andrewgodwin
0
580
The Scientist & The Engineer
andrewgodwin
1
680
Other Decks in Programming
See All in Programming
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
250
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
700
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
受け取る人から提供する人になるということ
little_rubyist
0
250
watsonx.ai Dojo #4 生成AIを使ったアプリ開発、応用編
oniak3ibm
PRO
1
150
ヤプリ新卒SREの オンボーディング
masaki12
0
130
距離関数を極める! / SESSIONS 2024
gam0022
0
290
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.5k
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
110
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
A better future with KSS
kneath
238
17k
GitHub's CSS Performance
jonrohan
1030
460k
Teambox: Starting and Learning
jrom
133
8.8k
Embracing the Ebb and Flow
colly
84
4.5k
Building Adaptive Systems
keathley
38
2.3k
Why Our Code Smells
bkeepers
PRO
334
57k
The Cult of Friendly URLs
andyhume
78
6k
Music & Morning Musume
bryan
46
6.2k
Transcript
Models & Migrations & Models & Migrations & Schemas –
oh my! Schemas – oh my! Andrew Godwin Andrew Godwin @andrewgodwin @andrewgodwin flickr.com/anders_young flickr.com/anders_young
· Django core dev · Django core dev · South
· South · Lanyrd · Lanyrd
· The Past · The Past django-evolution, south 0.1 django-evolution,
south 0.1 · The Present · The Present south 0.7 south 0.7 · The Future · The Future django 1.6? south 2.0? django 1.6? south 2.0?
· The Past · The Past django-evolution, south 0.1 django-evolution,
south 0.1 · The Present · The Present south 0.7 south 0.7 · The Future · The Future django 1.6? south 2.0? django 1.6? south 2.0?
Databases hate schema changes Databases hate schema changes “ “All
that optimising gone to waste...” All that optimising gone to waste...” flickr.com/96dpi flickr.com/96dpi
· Locks whole tables · Locks whole tables · Hammers
disk I/O · Hammers disk I/O · Causes inconsistent results · Causes inconsistent results
There's a code/schema split There's a code/schema split Your database
is going to ignore git Your database is going to ignore git flickr.com/nataliejohnson flickr.com/nataliejohnson
· Extra fields are fine · Extra fields are fine
· Missing fields are not · Missing fields are not · Painful/slow to sync · Painful/slow to sync
django-evolution django-evolution dmigrations dmigrations
South 0.1 South 0.1
None
None
· South 0.2 · South 0.2 mysql support mysql support
· South 0.3 · South 0.3 dependencies dependencies
· South 0.4 · South 0.4 altering columns altering columns
SQLite SQLite
· South 0.5 · South 0.5 ORM freezing ORM freezing
Automatic change detection Automatic change detection
· South 0.6 · South 0.6 Field introspection Field introspection
Dependency solving speed Dependency solving speed
· South 0.7 · South 0.7 data/schema split data/schema split
missing defaults for NOT NULL missing defaults for NOT NULL multidb multidb custom fields ignored custom fields ignored
· The Past · The Past django-evolution, south 0.1 django-evolution,
south 0.1 · The Present · The Present south 0.7 south 0.7 · The Future · The Future django 1.6? south 2.0? django 1.6? south 2.0?
· Mostly stable · Mostly stable Core API hasn't changed
for 2 years Core API hasn't changed for 2 years
· No rebase/collapse · No rebase/collapse Needs a big change
to migration tracking Needs a big change to migration tracking
· Opaque migrations · Opaque migrations Impossible to peek inside
migrations Impossible to peek inside migrations
· The Past · The Past django-evolution, south 0.1 django-evolution,
south 0.1 · The Present · The Present south 0.7 south 0.7 · The Future · The Future django 1.6? south 2.0? django 1.6? south 2.0?
django.db.backends.schema django.db.backends.schema
· Database abstraction layer · Database abstraction layer Has no
idea migrations exist Has no idea migrations exist
from django.db import connection from django.db import connection editor =
connection.schema_editor() editor = connection.schema_editor() editor.start() editor.start() editor.create_model(Author) editor.create_model(Author) editor.create_model(Book) editor.create_model(Book) editor.commit() editor.commit()
from django.db import connection from django.db import connection editor =
connection.schema_editor() editor = connection.schema_editor() editor.start() editor.start() editor.alter_field( editor.alter_field( Book, Book, CharField(max_length=100, db_index=True), CharField(max_length=100, db_index=True), TextField(), TextField(), ) ) editor.delete_field(Author, ”age”) editor.delete_field(Author, ”age”) editor.commit() editor.commit()
github.com/andrewgodwin/ github.com/andrewgodwin/ django/tree/schema-alteration django/tree/schema-alteration
contrib. contrib.migrations migrations
· Migration creation/running · Migration creation/running Would replace South Would
replace South
· Declarative migrations · Declarative migrations Combinable, optimisable Combinable, optimisable
· No frozen ORM · No frozen ORM Derived from
the migration history Derived from the migration history
· Raw SQL support · Raw SQL support For those
with beards For those with beards
· SQL output support · SQL output support For those
with full-flowing beards For those with full-flowing beards
from migrations.api import * from migrations.api import * class Migration(BaseMigration):
class Migration(BaseMigration): actions = [ actions = [ CreateModel(name = "Author", fields = [ CreateModel(name = "Author", fields = [ ("name", ("name", Field( Field( "django.db.models.fields.CharField", "django.db.models.fields.CharField", [], {"max_length": "100"} [], {"max_length": "100"} )), )), ]) ]) ] ]
github.com/andrewgodwin/migrations/ github.com/andrewgodwin/migrations/ Incomplete and broken code! Incomplete and broken code!
south 1.0 south 1.0
· Python 3 support · Python 3 support To coincide
with Django 1.5 To coincide with Django 1.5
· Will require Python 2.6 · Will require Python 2.6
As otherwise Python 3 is a PITA As otherwise Python 3 is a PITA
All subject to change! All subject to change! This isn't
set in stone. This isn't set in stone.
· Feedback on schema-alt branch · Feedback on schema-alt branch
How to help How to help · Weird and wacky use cases · Weird and wacky use cases · Come talk to me during sprints · Come talk to me during sprints
Questions? Questions? Andrew Godwin / @andrewgodwin Andrew Godwin / @andrewgodwin
flickr.com/oimax flickr.com/oimax