Web Frameworks
This page serves a reference guide for common tasks within web frameworks. Squawk doesn't have special support for Django or any other web ORM. This page is merely a guide.
#
Django ORMDjango can auto generate schema changes, but many times the generated SQL won't pass Squawk's rules. These custom database backends for zero downtime migrations might work for your use case:
#
making a field non-nullableIn the Django ORM, making a nullable field non-nullable requires care to make the change safe.
This example shows how to make a nullable boolean field a non-nullable field.
#
migration stepsWe cannot use the auto generated SQL from Django's migration system. We must use django.db.migrations.operations.SeparateDatabaseAndState
to make changes to our Django models while using custom SQL.
Update the model with a default so newly created objects in Django get assigned a default value. This change must be deployed before making the SQL migrations.
Create trigger to set default value
false
for insertspublished
isnull
.Set a default value for existing objects.
Create a not null constraint.
Validate constraint.
Remove trigger.
#
Alembic and SQLAlchemy#
usageor you can choose revisions
#
settingsUse transaction_per_migration = True
in configure
Set lock_timeout
and statement_timeout