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 full-size 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 full-size slide

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

    View full-size slide

  4. Migrations
    They're pretty good.

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  13. A New Format
    More concise
    Declarative
    Introspectable

    View full-size slide

  14. Migration actions
    Frozen ORM

    View full-size slide

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

    View full-size slide

  16. But what went wrong?

    View full-size slide

  17. Swappable Models

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  22. Unmigrated Apps

    View full-size slide

  23. Test persistence

    View full-size slide

  24. Test persistence
    on MySQL

    View full-size slide

  25. Random Meta options
    order_with_respect_to? Really?

    View full-size slide

  26. Proxy Models

    View full-size slide

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

    View full-size slide