tbicr / django-pg-zero-downtime-migrations

Django postgresql backend that apply migrations with respect to database locks
MIT License
525 stars 25 forks source link

update defaults handling #63

Closed tbicr closed 5 months ago

tbicr commented 5 months ago

This library consider add column with default operation is unsafe operation, it was actual for old versions that rewrite whole table to add default. New postgres versions changes only metadata so this operation is fast and can be considered as safe except cases when column added with default and not null that is not safe operation in case of django that use default only for filling data and drop db default after migration. Also adding column with default is much efficient operation than adding column and fulfill data manually.

In django 5.0 new db_default were added that assume add column with default (using db_default) is safe both for adding column with null and not null.

So in this MR whole approach to work with defaults were changed:

More details described in https://github.com/tbicr/django-pg-zero-downtime-migrations/issues/62

changes: