Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Django Migrations: A Retrospective

Django Migrations: A Retrospective

A talk I gave at DjangoCon AU 2014.

Andrew Godwin

August 01, 2014
Tweet

More Decks by Andrew Godwin

Other Decks in Programming

Transcript

  1. Andrew Godwin
    @andrewgodwin
    migrations:
    a retrospective

    View Slide

  2. Andrew Godwin
    Author of South migrations library
    Hi, I'm
    Author of 1.7 Django migrations
    I like my tea iced, and my schemas explicit

    View Slide

  3. Django/Python backend
    I work for
    Discovery? Mobile? Storage? UI?
    On-site? ...auditing? We have it all.
    We're hiring!

    View Slide

  4. Migrations
    They're pretty good.

    View Slide

  5. South
    ...it was good for its time

    View Slide

  6. The Initial Plan
    Django
    Schema backend
    ORM Hooks
    South 2
    Migration handling
    User interface

    View Slide

  7. The Revised Plan
    Django
    Schema backend
    ORM Hooks
    South 2
    Migration handling
    User interface
    Backport for 1.4 - 1.6

    View Slide

  8. The Revised Revised Plan
    Django
    Schema backend
    ORM Hooks
    Migration handling
    User interface

    View Slide

  9. Logically Separate
    SchemaEditor
    Schema Migrations
    field.deconstruct()
    ModelOptions.apps
    Operations
    Loader / Graph
    Executor
    Autodetector
    Optimiser
    State

    View Slide

  10. makemigrations
    field.deconstruct()
    Loader / Graph
    Autodetector Optimiser
    State
    Writer
    1
    2
    State
    3
    5
    4

    View Slide

  11. migrate
    SchemaEditor
    ModelOptions.apps
    Operations
    Loader / Graph Executor
    State
    1 2
    Recorder
    3

    View Slide

  12. Moving South into Django
    instead, "Adding migrations to Django"

    View Slide

  13. A New Format
    More concise
    Declarative
    Introspectable

    View Slide

  14. Migration actions
    Frozen ORM

    View Slide

  15. View Slide

  16. In-memory running
    Creates models from migration sets
    Autodetector diffs created from on-disk
    Used to feed SchemaEditor / ORM

    View Slide

  17. But what went wrong?

    View Slide

  18. Swappable Models

    View Slide

  19. Your migration dependencies
    myapp/0001
    myapp/0002
    otherapp/0001
    auth/0001
    contenttypes/0001

    View Slide

  20. myapp/0001
    myapp/0002
    otherapp/0001
    auth/0001
    contenttypes/0001
    thirdapp/0001
    Your migration dependencies
    on swappable models

    View Slide

  21. what?
    Your migration dependencies
    on swappable models
    myapp/0001
    myapp/0002
    otherapp/0001
    auth/0001
    contenttypes/0001
    thirdapp/0001
    ???

    View Slide

  22. what?
    Your migration dependencies
    on swappable models
    myapp/0001
    myapp/0002
    otherapp/0001
    auth/0001
    contenttypes/0001
    thirdapp/0001
    ???

    View Slide

  23. Unmigrated Apps

    View Slide

  24. Test persistence

    View Slide

  25. Test persistence
    on MySQL

    View Slide

  26. Random Meta options
    order_with_respect_to? Really?

    View Slide

  27. Proxy Models

    View Slide

  28. But we're close!
    Django 1.7, coming to a server near you soon.

    View Slide

  29. Thanks!
    Andrew Godwin
    [email protected]

    View Slide