Migrations & Templates

CIS1902 Python Programming

Reminders

  • HW3 is due next week. Please try to start early as there may be setup issues!
  • Start thinking about what you want your final projects to be, guidelines on the website.

Database Migrations

  • A database migration is the process of changing a database schema. Things that could be modified:
    • Table columns
    • Relationships (foreign keys)
    • Constraints (e.g. uniqueness)
  • Sort of like version control or git for your database schema.

Why is this hard?

  • In a production service, a migration requires locking the database. Needs special care, otherwise downtime will occur.
  • If migrations alter not just the schema but also data, rollbacks are complex if something goes wrong.
  • Large systems may have multiple databases that need to have coordinated migrations.

How do we deal with this in practice?

  • Simply shutdown system while running migrations.
    • Not a great user experience.
  • Ensure all migrations are backwards compatible. When a migration occurs, the new schema needs to play nicely with the current server code running.
    • If I remove a field in my migration, my old code will error once the migration goes through.
    • Instead, I need to remove all code usages of the field, deploy that code change, then finally do my database migration.

Django Lab: Votr