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

Everybody Loves Migrations

Andrew Godwin
September 04, 2013

Everybody Loves Migrations

A talk I gave at DjangoCon US 2013 about Django's new built-in migrations, South 2, and schema alteration.

Andrew Godwin

September 04, 2013
Tweet

More Decks by Andrew Godwin

Other Decks in Programming

Transcript

  1. What is schema alteration? Background Why wasn't it in Django

    before? Why are you doing all this anyway?
  2. Adding a field What is schema alteration? Changing unique_together Setting

    db_index=True Changing the type of a field Renaming a field Setting null=True Adding a model Deleting a model
  3. Adding a field What Django did before Changing unique_together Setting

    db_index=True Changing the type of a field Renaming a field Setting null=True Adding a model Deleting a model
  4. Basic Layout schemamigration: Creates migration files in apps datamigration: Also

    creates migration files in apps --auto: No, really, make them for me.
  5. Basic Layout schemamigration: Creates migration files in apps datamigration: Also

    creates migration files in apps migrate: Applies migrations only --auto: No, really, make them for me.
  6. Basic Layout schemamigration: Creates migration files in apps datamigration: Also

    creates migration files in apps migrate: Applies migrations only syncdb: Does no-migration apps. --auto: No, really, make them for me.
  7. Basic Layout schemamigration: Creates migration files in apps datamigration: Also

    creates migration files in apps migrate: Applies migrations only syncdb: Does no-migration apps. Occasionally does migrations. --auto: No, really, make them for me.
  8. Basic Layout schemamigration: Creates migration files in apps datamigration: Also

    creates migration files in apps migrate: Applies migrations only syncdb: Does no-migration apps. Occasionally does migrations. --auto: No, really, make them for me. test: Good luck with that one.
  9. Compound History Create Model Page with fields content, date Create

    Model Author with fields name, age Add title to Page Remove age from Author Migration 1 Migration 2 Migration 3 Model Page with fields title, content, date Model Author with field name
  10. Multiple AppCaches If you know what this means, well done.

    Basically, you can make multiple versions of the same model in memory at once.
  11. Schema backends PostgreSQL MySQL SQLite Oracle Migration Engine Dependency resolver

    Basic operations makemigrations migrate squashmigrations DONE DONE DONE DONE DONE DONE DONE DONE NOT YET Advanced operations NOT YET Autodetector PARTIAL
  12. Don't Panic! syncdb and signals still work Upgrade path from

    South migrations South 2 to backport new format
  13. Don't Panic! syncdb and signals still work Upgrade path from

    South migrations South 2 to backport new format Slightly Panic! Custom fields will need some work
  14. New migration format Django models through and through Please use

    a proper database Schemas are your friend. Even easier to use