Commit 3e10ab2
committed
Move column nullability and DEFAULT ownership to convergence
Removes the schema editor's 4-way backfill for nullable -> NOT NULL
transitions and delegates nullability + column DEFAULT reconciliation
entirely to convergence, which already handles them with online-safe
DDL (CHECK NOT VALID -> VALIDATE -> SET NOT NULL; catalog-only
SET/DROP DEFAULT).
- Add allow_null to the previously named non_db_attrs so the schema
editor short-circuits nullability-only alters, same pattern that
already covered default=.
- Rename non_db_attrs -> non_migration_attrs. Post-refactor the
attribute covers allow_null, default, on_delete — all real DB
concepts, just not owned by migrations. "non_db" was a Django-ism
that no longer matches Plain's architecture.
- Strip non_migration_attrs in the autodetector before deciding to
emit AlterField, so migration files no longer carry no-op operations
for nullability/default/on_delete/choices-only diffs. These were
previously generated and silently short-circuited at apply time.
- Delete the autodetector's "alter nullable -> NOT NULL without
default" MigrationSchemaError. Convergence reports NullabilityDrift
with has_null_rows=True as a blocked fix and tells the user to
backfill; no longer a structural failure.
- Delete unused schema editor helpers (_alter_column_null_sql,
_alter_column_default_sql), SQL templates (sql_alter_column_null /
_not_null / _default, sql_update_with_default / _db_default), and
the dead sql_alter_column_type class attr. Clean up the unused
new_type param on _rename_field_sql.
- Simplify _alter_column_type_sql: drops the always-[] post_actions
tuple and the model / old_field parameters it never used; uses a
local variable instead of mutating self.sql_alter_column_type on
each call.
- README: add "How do I make an existing column NOT NULL?" FAQ.
Update the add-a-field FAQ to point at the convergence-driven flow
(add allow_null=True, data-migrate, remove allow_null=True). Drop
the 4-way backfill example from the DDL-timeouts paragraph.
Upgrade path: projects upgrading will keep any historical AlterField
operations from past allow_null flips. These re-apply via the schema
editor, which now no-ops on those diffs, so migrate apply is safe.
The first postgres sync after upgrade will surface NullabilityDrift
for any column whose DB state disagrees with the model — intended
behavior; convergence applies SetNotNullFix automatically if no NULL
rows exist, or blocks with guidance if they do.1 parent 07cb500 commit 3e10ab2
9 files changed
Lines changed: 155 additions & 474 deletions
File tree
- plain-postgres
- plain/postgres
- fields
- migrations
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
693 | 693 | | |
694 | 694 | | |
695 | 695 | | |
696 | | - | |
| 696 | + | |
697 | 697 | | |
698 | 698 | | |
699 | 699 | | |
| |||
1222 | 1222 | | |
1223 | 1223 | | |
1224 | 1224 | | |
1225 | | - | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
1226 | 1233 | | |
1227 | 1234 | | |
1228 | 1235 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
| 135 | + | |
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| |||
536 | 536 | | |
537 | 537 | | |
538 | 538 | | |
539 | | - | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
540 | 545 | | |
541 | 546 | | |
542 | 547 | | |
| |||
642 | 647 | | |
643 | 648 | | |
644 | 649 | | |
645 | | - | |
| 650 | + | |
646 | 651 | | |
647 | 652 | | |
648 | 653 | | |
| |||
700 | 705 | | |
701 | 706 | | |
702 | 707 | | |
703 | | - | |
| 708 | + | |
704 | 709 | | |
705 | 710 | | |
706 | 711 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
100 | 104 | | |
101 | 105 | | |
102 | 106 | | |
| |||
359 | 363 | | |
360 | 364 | | |
361 | 365 | | |
362 | | - | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
363 | 371 | | |
364 | 372 | | |
365 | 373 | | |
| |||
Lines changed: 24 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
30 | 41 | | |
31 | 42 | | |
32 | 43 | | |
| |||
804 | 815 | | |
805 | 816 | | |
806 | 817 | | |
807 | | - | |
808 | | - | |
809 | | - | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
810 | 821 | | |
811 | 822 | | |
812 | 823 | | |
| |||
898 | 909 | | |
899 | 910 | | |
900 | 911 | | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
901 | 922 | | |
902 | 923 | | |
903 | 924 | | |
| |||
907 | 928 | | |
908 | 929 | | |
909 | 930 | | |
910 | | - | |
911 | | - | |
912 | | - | |
913 | | - | |
914 | | - | |
915 | | - | |
916 | | - | |
917 | | - | |
918 | | - | |
919 | | - | |
920 | | - | |
921 | | - | |
922 | | - | |
923 | | - | |
924 | | - | |
925 | | - | |
926 | | - | |
927 | | - | |
928 | | - | |
929 | | - | |
930 | 931 | | |
931 | 932 | | |
932 | 933 | | |
| |||
0 commit comments