Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update defaults handling #63

Merged
merged 1 commit into from
Jun 3, 2024
Merged

Conversation

tbicr
Copy link
Owner

@tbicr tbicr commented May 29, 2024

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:

  • add column default null - safe operation, after migration null values can be presented in db
  • add column default not null is unsafe operation
  • add column db_default both null and not null - safe operation, after migration no nulls can be presented in db
  • add column default for django < 5.0 and ZERO_DOWNTIME_MIGRATIONS_KEEP_DEFAULT=True - safe operation, after migration no nulls can be presented in db, provide same behavior as db_default

More details described in #62

changes:

  • changed ADD COLUMN DEFAULT NULL to safe operation for code default
  • changed ADD COLUMN DEFAULT NOT NULL to safe operation for db_default in django 5.0+
  • added ZERO_DOWNTIME_MIGRATIONS_KEEP_DEFAULT settings and changed ADD COLUMN DEFAULT NOT NULL with this settings to safe operation for django<5.0
  • updated unsafe migrations links to documentation
  • updated patched code to latest django version
  • improved README

@tbicr tbicr force-pushed the change-add-column-default-behaviour branch 4 times, most recently from cca9cf9 to 7d4b4ab Compare May 29, 2024 15:38
@tbicr tbicr force-pushed the change-add-column-default-behaviour branch from 7d4b4ab to f18d393 Compare May 29, 2024 16:50
@tbicr tbicr merged commit 8645ff2 into master Jun 3, 2024
2 checks passed
@tbicr tbicr deleted the change-add-column-default-behaviour branch June 3, 2024 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant