django-compose 0.1.0.dev12__tar.gz → 0.1.0.dev14__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/CHANGELOG.md +66 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/PKG-INFO +6 -2
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/README.md +5 -1
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/docs/ROADMAP.md +9 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/docs/SPEC.md +238 -24
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/docs/api.md +9 -4
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/docs/extensions.md +1 -1
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/docs/migrations.md +70 -33
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/docs/packaging.md +14 -0
- django_compose-0.1.0.dev14/docs/proposals/0005-migrate-time-drop-guard.md +154 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/docs/provisioning.md +6 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/pyproject.toml +1 -1
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/scripts/check_distribution.py +1 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/apps.py +3 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/declarations.py +3 -2
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/management/__init__.py +33 -1
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/management/commands/makemigrations.py +1 -1
- django_compose-0.1.0.dev14/src/django_compose/management/commands/migrate.py +40 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/management/commands/provision.py +4 -2
- django_compose-0.1.0.dev14/src/django_compose/migrations.py +2011 -0
- django_compose-0.1.0.dev14/src/django_compose/operations.py +24 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/provision.py +36 -18
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/snapshot.py +1 -1
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/sources.py +52 -11
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_boundaries.py +22 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_history.py +79 -2
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_migrations.py +49 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_migrations_guards.py +17 -4
- django_compose-0.1.0.dev14/tests/test_migrations_plan_guard.py +4207 -0
- django_compose-0.1.0.dev14/tests/test_migrations_postgres.py +619 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_provision.py +215 -3
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_snapshot.py +16 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_sources.py +23 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/uv.lock +1 -1
- django_compose-0.1.0.dev12/src/django_compose/management/commands/migrate.py +0 -18
- django_compose-0.1.0.dev12/src/django_compose/migrations.py +0 -691
- django_compose-0.1.0.dev12/tests/test_migrations_postgres.py +0 -198
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/.gitignore +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/AGENTS.md +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/CONTRIBUTING.md +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/COPYING +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/LICENSE +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/Makefile +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/NOTICE +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/docs/README.md +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/docs/components.md +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/docs/configuration.md +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/docs/dependencies.md +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/docs/models.md +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/docs/proposals/0001-native-url-collisions.md +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/docs/proposals/0002-supplied-distribution-metadata.md +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/docs/proposals/0004-serving-boundary.md +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/docs/proposals/README.md +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/docs/quickstart.md +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/examples/shop/.gitignore +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/examples/shop/README.md +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/examples/shop/catalog/__init__.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/examples/shop/catalog/apps.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/examples/shop/catalog/autoconfig.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/examples/shop/catalog/integrations.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/examples/shop/catalog/models.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/examples/shop/catalog/pyproject.toml +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/examples/shop/catalog/schema.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/examples/shop/catalog/urls.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/examples/shop/manage.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/examples/shop/reviews/__init__.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/examples/shop/reviews/apps.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/examples/shop/reviews/autoconfig.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/examples/shop/reviews/models.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/examples/shop/reviews/pyproject.toml +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/examples/shop/settings.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/examples/shop/urls.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/examples/shop/verify.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/__init__.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/__main__.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/artifacts.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/autoreload.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/build.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/cli.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/components.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/conf.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/history.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/management/commands/__init__.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/management/commands/check_migrations.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/management/commands/compose.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/management/commands/reset_migration_history.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/management/commands/retire_history.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/migration_imports.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/model_composition.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/models.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/py.typed +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/rendering.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/serving.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/src/django_compose/typing.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/core_fixtures/__init__.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_artifacts.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_autoreload.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_bootstrap.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_components.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_conf.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_initial_history.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_integrations.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_launcher.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_migration_imports.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_migration_scaffold.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_models.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_provision_postgres.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_startup.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/test_typing.py +0 -0
- {django_compose-0.1.0.dev12 → django_compose-0.1.0.dev14}/tests/typing_fixtures/__init__.py +0 -0
|
@@ -1,5 +1,71 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.0.dev14
|
|
4
|
+
|
|
5
|
+
- Apply the [drop guard](docs/SPEC.md#drop-guard) when `migrate` runs, and so in
|
|
6
|
+
`provision`, also under `--skip-checks`: a pending removal in the history the project
|
|
7
|
+
owns is refused before any operation runs where it would destroy stored data or delete
|
|
8
|
+
a table another model still owns, or where the guard cannot prove that it would not.
|
|
9
|
+
Previously only autodetected removals were judged, at `makemigrations`, so a removal
|
|
10
|
+
migration already on disk was applied unchecked. The specification states what the
|
|
11
|
+
guard judges, on which databases, and what it leaves undetected; see
|
|
12
|
+
[proposal 0005](docs/proposals/0005-migrate-time-drop-guard.md) for the decisions.
|
|
13
|
+
- Add `django_compose.operations.IntendedRemoveField` and `IntendedDeleteModel` to
|
|
14
|
+
declare a drop a migration intends; see
|
|
15
|
+
[intended drops](docs/migrations.md#declare-an-intended-drop).
|
|
16
|
+
- Report another app's `migrate` or `makemigrations` that shadows this package's, and
|
|
17
|
+
so switches the drop guard off, with system check `django_compose.E002`, tagged
|
|
18
|
+
`commands`. Before any database work `provision` refuses a shadowing `migrate`, and
|
|
19
|
+
whatever the `commands` checks report unless it is silenced; see the
|
|
20
|
+
[drop guard](docs/SPEC.md#drop-guard).
|
|
21
|
+
- `retire_history --purge` applies only the retired label's own migrations.
|
|
22
|
+
- `django_compose.provision.TABLE` and `LEGACY_TABLE` are gone: the provision record's
|
|
23
|
+
table name is `ProvisionRecorder.Record._meta.db_table`, read from the model that owns
|
|
24
|
+
it, and the name `provision --upgrade-from` renames is `ProvisionRecorder.legacy_table`.
|
|
25
|
+
- The drop guard proves storage empty with one EXISTS query, or two for a column of a
|
|
26
|
+
table that holds rows, and counts rows only for a refusal. On a database that stores
|
|
27
|
+
data it walks and renders the whole pending plan before the first operation, so
|
|
28
|
+
`migrate` there takes longer on a large plan: a few seconds for two hundred pending
|
|
29
|
+
migrations of a composed host on an idle machine, several times that on a loaded one.
|
|
30
|
+
Deleting a table another model still owns is refused in the same words, with the
|
|
31
|
+
same remedy, at `makemigrations`, `migrate` and `retire_history --purge`.
|
|
32
|
+
- `check_migrations`, and so `provision`, builds native history's state from copies of
|
|
33
|
+
the migration operations. Django rewrites in place the fields that reference a renamed
|
|
34
|
+
field, so a history renaming a field that another model's `to_field` names failed to
|
|
35
|
+
migrate after the check in the same process.
|
|
36
|
+
- `SourceResolver.installed(module)` tells whether an installed distribution owns a
|
|
37
|
+
module, settled by the first owner found rather than the full index.
|
|
38
|
+
- **Upgrade impact:** a host whose unapplied history removes a column or table that
|
|
39
|
+
still holds data is now refused at `migrate` and `provision`, which is the point.
|
|
40
|
+
Review each named removal: keep the storage, or move its data and write the removal as
|
|
41
|
+
`IntendedRemoveField(model_name=..., name=...)` or `IntendedDeleteModel(name=...)` in
|
|
42
|
+
that migration. Deleting a table another model still owns is refused even when
|
|
43
|
+
declared: keep the table, or change that owner first. A pending purge migration is
|
|
44
|
+
refused the same way; apply it on each deployment with `retire_history <label>
|
|
45
|
+
--purge`. Where the guard cannot read the migration state, as where a history leaves a
|
|
46
|
+
relation's target undefined for a while, it refuses under `cannot prove migration drop
|
|
47
|
+
safe` each table drop it cannot read, each table drop whose owners at the end of the
|
|
48
|
+
plan it cannot tell, and, on a database that stores data, each undeclared removal from
|
|
49
|
+
there on; where it cannot copy an operation or move the state, every removal from
|
|
50
|
+
there on. Where the state renders again after a later migration, or the walk ended at
|
|
51
|
+
an operation it cannot copy, a refusal names that migration: migrate to it first, then
|
|
52
|
+
migrate. Otherwise order the history as the refusal says. Any other installed app, the
|
|
53
|
+
project's or a third party's, that ships a `migrate` or `makemigrations` command now
|
|
54
|
+
fails system check `django_compose.E002` and makes `provision` refuse: remove that
|
|
55
|
+
command, or make it subclass this package's. A `makemigrations` that must stay, such
|
|
56
|
+
as django-linear-migrations', keeps the guard as a command subclassing both, as
|
|
57
|
+
`class Command(LinearCommand, ComposeCommand)`, with nothing silenced; silencing
|
|
58
|
+
`django_compose.E002` and `commands.E001` instead provisions, but authors without the
|
|
59
|
+
guard.
|
|
60
|
+
|
|
61
|
+
## 0.1.0.dev13
|
|
62
|
+
|
|
63
|
+
- Include each selected component's resolved `path` in the snapshot digest. A
|
|
64
|
+
component that moved with identical bytes, such as an editable install replacing
|
|
65
|
+
a site-packages copy or a moved checkout, left the digest unchanged, so
|
|
66
|
+
`compose --if-stale` reported the composition current while the emitted roots
|
|
67
|
+
still named the old location, which might no longer exist.
|
|
68
|
+
|
|
3
69
|
## 0.1.0.dev12
|
|
4
70
|
|
|
5
71
|
- Rebase each composition target on its own target first in `django_compose.typing`,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: django-compose
|
|
3
|
-
Version: 0.1.0.
|
|
3
|
+
Version: 0.1.0.dev14
|
|
4
4
|
Summary: Compose reusable Django apps into a runnable project.
|
|
5
5
|
Project-URL: Source, https://github.com/ang-ee/django-compose
|
|
6
6
|
Project-URL: Documentation, https://github.com/ang-ee/django-compose/tree/main/docs
|
|
@@ -81,13 +81,17 @@ project:
|
|
|
81
81
|
```sh
|
|
82
82
|
python manage.py compose # Generate models, app configs and declared artifacts
|
|
83
83
|
python manage.py makemigrations # Author ordinary Django migration files
|
|
84
|
-
python manage.py migrate # Apply them
|
|
84
|
+
python manage.py migrate # Apply them, refusing undeclared drops of stored data
|
|
85
85
|
python manage.py runserver # Run Django's development server
|
|
86
86
|
```
|
|
87
87
|
|
|
88
88
|
Django owns the app registry, ORM, managers, querysets and migration history.
|
|
89
89
|
Generated classes import the source apps, so keep their packages installed.
|
|
90
90
|
Rebuild generated code as apps change; preserve and review migration files.
|
|
91
|
+
`makemigrations` refuses to write a migration that would remove a column or table
|
|
92
|
+
still holding data, and `migrate` refuses to apply one in the project's own history
|
|
93
|
+
unless it declares that drop; see the
|
|
94
|
+
[drop guard](https://github.com/ang-ee/django-compose/blob/main/docs/migrations.md#advanced-the-drop-guard-and-history-cutoffs).
|
|
91
95
|
|
|
92
96
|
## Get started
|
|
93
97
|
|
|
@@ -59,13 +59,17 @@ project:
|
|
|
59
59
|
```sh
|
|
60
60
|
python manage.py compose # Generate models, app configs and declared artifacts
|
|
61
61
|
python manage.py makemigrations # Author ordinary Django migration files
|
|
62
|
-
python manage.py migrate # Apply them
|
|
62
|
+
python manage.py migrate # Apply them, refusing undeclared drops of stored data
|
|
63
63
|
python manage.py runserver # Run Django's development server
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
Django owns the app registry, ORM, managers, querysets and migration history.
|
|
67
67
|
Generated classes import the source apps, so keep their packages installed.
|
|
68
68
|
Rebuild generated code as apps change; preserve and review migration files.
|
|
69
|
+
`makemigrations` refuses to write a migration that would remove a column or table
|
|
70
|
+
still holding data, and `migrate` refuses to apply one in the project's own history
|
|
71
|
+
unless it declares that drop; see the
|
|
72
|
+
[drop guard](https://github.com/ang-ee/django-compose/blob/main/docs/migrations.md#advanced-the-drop-guard-and-history-cutoffs).
|
|
69
73
|
|
|
70
74
|
## Get started
|
|
71
75
|
|
|
@@ -15,5 +15,14 @@ Current boundaries and remaining verification:
|
|
|
15
15
|
Watchman daemon remains outstanding.
|
|
16
16
|
- CI and publication still need one shared mandatory PostgreSQL check gate and
|
|
17
17
|
exact checked-archive transfer. The migration candidate is not release-ready.
|
|
18
|
+
- `ProvisionRecorder.legacy_table` names `base_provision`, a consumer's legacy table,
|
|
19
|
+
for `provision --upgrade-from`, although this package names no consumer. Retire the
|
|
20
|
+
option, and that name, once the cutover window closes.
|
|
21
|
+
- On a database that stores nothing, the drop guard refuses a table drop inside a render
|
|
22
|
+
window: where Django cannot render afresh the state just before the drop, as between a
|
|
23
|
+
history's deletion of a model another model still references and its removal of that
|
|
24
|
+
reference, the guard cannot read the dropped model's tables or who owns them, as the
|
|
25
|
+
[drop guard](SPEC.md#drop-guard) states. Rendering a copy of that state with its
|
|
26
|
+
dangling relations set aside would read them, and lift that refusal.
|
|
18
27
|
|
|
19
28
|
Changes to a public contract use the [proposal process](proposals/README.md).
|
|
@@ -31,6 +31,9 @@ defines supported versions and platforms.
|
|
|
31
31
|
Each component currently provides one Django app. Distribution names, Python
|
|
32
32
|
import paths and native app identities remain distinct.
|
|
33
33
|
- A **snapshot** is the immutable set of composition inputs and their digest.
|
|
34
|
+
The digest covers each selected component's resolved `path`, so a component
|
|
35
|
+
that moves (an editable install replacing a site-packages copy, or a moved
|
|
36
|
+
checkout) changes it even when its bytes are identical.
|
|
34
37
|
A **build record**, represented by `serving.Receipt`, records generated-file
|
|
35
38
|
hashes and retained migration labels in the generated package.
|
|
36
39
|
- A **history-only app** retains a Django app label for migrations after the
|
|
@@ -284,7 +287,9 @@ subdirectories, including any directory named `web`, are ordinary source inputs.
|
|
|
284
287
|
directories and then `sys.path`, without executing parent packages. Path-only
|
|
285
288
|
lookups for fingerprints, serving and reload inputs do not inspect distribution
|
|
286
289
|
metadata. Migration import audits additionally determine providers through exact
|
|
287
|
-
RECORD or PEP 610 ownership, with one lazy index per audit.
|
|
290
|
+
RECORD or PEP 610 ownership, with one lazy index per audit. The drop guard asks only
|
|
291
|
+
whether a distribution owns a migration package, which the first RECORD or PEP 610
|
|
292
|
+
project found to name it settles before that index is built. Native app/config
|
|
288
293
|
modules are imported to select configurations and must remain safe before Django
|
|
289
294
|
setup. Snapshot and serving do not import the model compiler or execute integrations.
|
|
290
295
|
|
|
@@ -346,8 +351,10 @@ the same rule for native dispatch.
|
|
|
346
351
|
|
|
347
352
|
## Integration protocols
|
|
348
353
|
|
|
349
|
-
Ordered `COMPOSE_INTEGRATIONS` classes are instantiated once during build and
|
|
350
|
-
|
|
354
|
+
Ordered `COMPOSE_INTEGRATIONS` classes are instantiated once during build, and the
|
|
355
|
+
[drop guard](#drop-guard) instantiates them once per run for their `MigrationPolicy`
|
|
356
|
+
exemptions. They implement one or more independent protocols from
|
|
357
|
+
`django_compose.declarations`:
|
|
351
358
|
|
|
352
359
|
- `ModelDeclarationHook.model_declaration(composition, source) -> ModelDeclaration`.
|
|
353
360
|
- `ArtifactHook.external_root`, `phase` (`"models"` or `"ready"`) and
|
|
@@ -454,7 +461,7 @@ All package migration comparisons use this state calculation.
|
|
|
454
461
|
autodetector. Django owns `--check`, `--dry-run`, `--empty`, `--merge`, `--update`,
|
|
455
462
|
serialization and file destinations. There is no custom multi-phase authoring or
|
|
456
463
|
whole-command rollback journal; native command semantics apply. Authoring may
|
|
457
|
-
read routed databases for
|
|
464
|
+
read routed databases for the [drop guard](#drop-guard), but does not write migration
|
|
458
465
|
recorder rows. Native `migrate` owns application and recording.
|
|
459
466
|
|
|
460
467
|
`migrations.check_native_history(apps, *, labels)` compares native graph state
|
|
@@ -463,27 +470,18 @@ reads retained labels from the build record. Compiler revision is 2; the receipt
|
|
|
463
470
|
schema is unchanged. For the prerelease cutoff and retained historical files,
|
|
464
471
|
see [upgrade guidance](migrations.md#upgrade-from-the-removed-prerelease-protocol).
|
|
465
472
|
|
|
466
|
-
`DropGuardAutodetector`, shared by native `makemigrations` and `migrate`, requires
|
|
467
|
-
relevant rows or columns to be empty on every database eligible for the native
|
|
468
|
-
operation before automatic destructive changes. Eligibility includes native
|
|
469
|
-
model options and routers. Shared-table protection is per alias and includes
|
|
470
|
-
implicit many-to-many storage deleted with its owning model or field. Quoted identifiers
|
|
471
|
-
are resolved through backend semantics; unsupported or uncertain storage identity
|
|
472
|
-
and unavailable eligible databases cannot prove safety. Explicit integration-owned
|
|
473
|
-
row exemptions use `MigrationPolicy`. See the [storage proof's supported cases
|
|
474
|
-
and limits](migrations.md#advanced-destructive-changes-and-history-cutoffs).
|
|
475
|
-
|
|
476
473
|
Retirement requires consistent fully applied history across all configured
|
|
477
|
-
migration-relevant aliases and refuses retained incoming cross-app dependencies.
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
clean
|
|
474
|
+
migration-relevant aliases and refuses retained incoming cross-app dependencies. The
|
|
475
|
+
alias scope includes native data-operation routing hints; custom database behavior
|
|
476
|
+
that cannot establish a narrower scope requires all configured aliases. Optional purge
|
|
477
|
+
authors/applies a final native deletion migration on that same alias scope, applying
|
|
478
|
+
only the retired label's migrations and naming a targeted `migrate <app> <name>` for
|
|
479
|
+
any other app's pending migration in its chain, since a full `migrate` would reach the
|
|
480
|
+
purge; purge alone is not retirement. Successful retirement updates the record; the
|
|
481
|
+
next compose removes the history-only config. Databases absent from command settings
|
|
482
|
+
lie outside that proof. Guarded history reset additionally requires a fully applied,
|
|
483
|
+
model-clean graph and uses transactional recorder changes with filesystem rollback
|
|
484
|
+
preserving original bytes and permissions. Normal build and clean never reset history.
|
|
487
485
|
|
|
488
486
|
`check_migrations` checks native state.
|
|
489
487
|
`check_migrations --imports` statically audits selected migration sources,
|
|
@@ -495,6 +493,222 @@ no migration operations. `--imports --removing DIST...` refuses enabled provider
|
|
|
495
493
|
retained imports, unresolved/unsupported entries and loader failures; it does not
|
|
496
494
|
uninstall anything. See [migration workflows](migrations.md).
|
|
497
495
|
|
|
496
|
+
### Drop guard
|
|
497
|
+
|
|
498
|
+
The drop guard refuses a native removal that would destroy stored data. A removal is a
|
|
499
|
+
`RemoveField` or `DeleteModel`, also one among the database operations of a
|
|
500
|
+
`SeparateDatabaseAndState`. It drops a concrete field's column, a field's implicit
|
|
501
|
+
many-to-many table, or a model's table; an explicit through model owns no storage of its
|
|
502
|
+
own, and a generated column holds no data of its own. Storage is empty when no row holds
|
|
503
|
+
data in it, read without the model's managers: a nullable column is empty at NULL and a
|
|
504
|
+
non-null column at its native default, while a database default cannot prove emptiness.
|
|
505
|
+
Rows a deleted table still holds may be retired explicitly by
|
|
506
|
+
`MigrationPolicy.retired_primary_keys(model, alias)`. Eligibility follows native model
|
|
507
|
+
options and routers. Storage identity follows the backend's own rules: on PostgreSQL
|
|
508
|
+
quoted case, explicit schemas and `search_path`, and on SQLite its case rule and the
|
|
509
|
+
temporary tables it resolves first. Attached SQLite databases, an identifier Django's
|
|
510
|
+
`split_identifier` does not represent faithfully, a namespace on another backend, a name
|
|
511
|
+
over the backend's length limit, and an unavailable eligible database cannot prove a
|
|
512
|
+
drop safe. A table that an active model still owns on the same alias is never deleted,
|
|
513
|
+
even when empty; identical names on disjoint aliases are not shared. An unmanaged, proxy
|
|
514
|
+
or swapped model owns no table, since Django neither creates nor deletes one for it, so
|
|
515
|
+
it keeps no table from deletion; the rows of that table remain protected.
|
|
516
|
+
|
|
517
|
+
It runs at two points on these rules:
|
|
518
|
+
|
|
519
|
+
- **Authoring:** `DropGuardAutodetector`, shared by native `makemigrations` and
|
|
520
|
+
`migrate`, refuses an autodetected removal unless every eligible configured database
|
|
521
|
+
proves it safe, and refuses deleting a table that the target state still owns. It
|
|
522
|
+
judges whatever the command autodetects for the apps it is given; it has no scope
|
|
523
|
+
of its own.
|
|
524
|
+
- **Applying:** the package's `migrate` judges the plan it is about to run from
|
|
525
|
+
`pre_migrate`, before the syncdb phase and the first operation, also under
|
|
526
|
+
`--skip-checks`, through `migrations.check_plan_drops(plan, *, using)`. It judges a
|
|
527
|
+
forward plan on the alias being migrated, on the graph native `migrate` planned with,
|
|
528
|
+
including for a squash-replaced target, in the order the executor applies it. A
|
|
529
|
+
planned migration the walk cannot follow is refused by name. What happens where the
|
|
530
|
+
walk's own work raises depends on whether its state can still move. Where copying an
|
|
531
|
+
operation that can change the state, or moving the state with one, raises, the state
|
|
532
|
+
is lost and the walk ends: every removal in the history the guard judges from there
|
|
533
|
+
on is refused, whatever its kind and on every database, since without the state a
|
|
534
|
+
field's removal cannot be told from a many-to-many table's, and so is every table
|
|
535
|
+
drop it met, whose owners at the end of the plan cannot be told. Where rendering or
|
|
536
|
+
reading the state raises instead, as where Django cannot render afresh a state that
|
|
537
|
+
native `migrate`, keeping its rendering current in place, applies, the state still
|
|
538
|
+
moves, as Django moves it, and the walk goes blind, whichever history left the state so. A
|
|
539
|
+
blind walk reads no model and refuses each removal in the history the guard judges
|
|
540
|
+
that it would have to read: every one that can drop a table, which the unrendered
|
|
541
|
+
state tells, and, where data is stored, every undeclared one, however empty. A
|
|
542
|
+
declared column drop needs no proof and applies, and where nothing is stored a column
|
|
543
|
+
removal is not refused. After each later migration a blind walk tries to render its
|
|
544
|
+
state afresh, as native `migrate` renders the state it starts from, and where it can,
|
|
545
|
+
it reads its state again. Names moved unfollowed meanwhile, so from the first time it
|
|
546
|
+
goes blind the walk follows no name and proves nothing: where data is stored it
|
|
547
|
+
refuses every undeclared removal it judges, and it tells who owns the tables it drops,
|
|
548
|
+
met before it went blind or after it reads again, from names alone at the end of the
|
|
549
|
+
plan. Where the state at the end of the plan does not render, every table drop it met
|
|
550
|
+
is refused. The refusals name what was raised, and raise from it; a plan with no such
|
|
551
|
+
removal applies as native `migrate` applies it. Whatever the guard itself raises
|
|
552
|
+
outside its walk refuses the plan in the same way.
|
|
553
|
+
|
|
554
|
+
At `migrate`:
|
|
555
|
+
|
|
556
|
+
- **Nothing stored:** an alias whose only tables are Django's migration recorder and
|
|
557
|
+
`provision`'s record, such as a fresh or test database on PostgreSQL or SQLite, holds
|
|
558
|
+
no data to lose, so the guard probes nothing there. It follows the plan's renames
|
|
559
|
+
there only where the shared-table rule would otherwise refuse a removal in the history
|
|
560
|
+
it judges, to tell whether the plan put storage of its own under the dropped table's
|
|
561
|
+
name. Only a complete inventory shows that the alias stores nothing: PostgreSQL's
|
|
562
|
+
catalog across every schema, in which a relation an extension owns, such as PostGIS's
|
|
563
|
+
`spatial_ref_sys`, does not count, or SQLite's main database with nothing attached; on
|
|
564
|
+
other backends the guard always probes. `--fake-initial` adoption finds tables, so it
|
|
565
|
+
is probed. The shared-table rule needs no data and still applies, from names alone:
|
|
566
|
+
names only a catalog could tell apart are refused. Elsewhere the catalog tells them
|
|
567
|
+
apart only where it holds both before the plan, since the plan may create a name it
|
|
568
|
+
lacks.
|
|
569
|
+
- **Scope:** the history the project owns: the build record's `HISTORY_LABELS` and
|
|
570
|
+
every project-source app, one whose migration package no installed distribution
|
|
571
|
+
owns, as the retained-import audit's resolver classifies it. Django's and installed
|
|
572
|
+
third-party apps' history belongs to their owners. A project installed as a
|
|
573
|
+
distribution keeps its composed history judged, but its other apps then classify as
|
|
574
|
+
installed, so `migrate` does not judge their history although `makemigrations`
|
|
575
|
+
still guards what it autodetects for them. That includes an editable install, such
|
|
576
|
+
as `uv sync` or `pip install -e` makes, which records the project directory as PEP
|
|
577
|
+
610 `dir_info`.
|
|
578
|
+
- **Probe:** the plan's state at each removal routes it and tells only what Django
|
|
579
|
+
drops: the model's tables, a many-to-many field's table, or a field's column, which a
|
|
580
|
+
field without a database type does not have. That storage is probed under the name it
|
|
581
|
+
had before the plan. A column is judged by the definition the state before the plan
|
|
582
|
+
gives it, on a model that migrates on the alias, under which its rows were written,
|
|
583
|
+
whatever the plan redefines in any form or under any name: its class, `null`,
|
|
584
|
+
`default` or `db_default`, from which Django derives its default, or whether it is
|
|
585
|
+
generated. A table without rows proves every column such a definition stores in it
|
|
586
|
+
empty without any default; a column no field of that state is stored in stays unproved,
|
|
587
|
+
rows or none. Where the table holds rows, the guard calls the callable `default` of
|
|
588
|
+
each such definition
|
|
589
|
+
once for each column it proves, at `pre_migrate`: that runs the history's code before
|
|
590
|
+
the plan, and what it writes stays written even where the plan is refused. A column
|
|
591
|
+
generated before the plan holds no data of its own, while one the
|
|
592
|
+
plan redefines as generated still holds the rows written before it. Where no field
|
|
593
|
+
of that state is stored in the column, as for a table `--fake-initial` adopts, or
|
|
594
|
+
where the fields stored in it read as empty differently, the column cannot be proved
|
|
595
|
+
empty. Nor can any storage whose proof raises anything while the guard builds or reads
|
|
596
|
+
it, such as a field that cannot be resolved or a default that raises or that the
|
|
597
|
+
query's lookup rejects: that leaves the storage unproved, naming what was raised, and
|
|
598
|
+
never stops `migrate` itself. The walk follows every rename the plan's database
|
|
599
|
+
operations make, whoever owns them: `AlterModelTable`, `RenameModel`, `RenameField`
|
|
600
|
+
and `AlterField`. It follows each where Django applies it, on an alias that migrates
|
|
601
|
+
the model the operation produces, so a swapped model or one routed elsewhere renames
|
|
602
|
+
nothing. A subclass that replaces Django's `database_forwards` runs custom database
|
|
603
|
+
code, which is not followed. Two spellings of a name that the backend does not tell
|
|
604
|
+
apart name the same storage: a rename between them moves nothing, and storage under
|
|
605
|
+
either is present. Case does not tell table names apart where Django's
|
|
606
|
+
`ignores_table_name_case` is set, as on SQLite, nor column names on SQLite and MySQL
|
|
607
|
+
whatever MySQL's table-name setting, nor any name where the backend's quoting folds
|
|
608
|
+
case, as Oracle's does. SQLite folds the case of ASCII letters only, and the guard
|
|
609
|
+
folds names that way on SQLite and on MySQL; for MySQL that is simulated, not verified
|
|
610
|
+
on a server, which may fold other letters too. Where quoting folds case, the guard
|
|
611
|
+
compares names as Django quotes them. Only SQLite and PostgreSQL have real-backend
|
|
612
|
+
coverage. A name that an earlier rename or removal of the plan vacated holds the
|
|
613
|
+
plan's own storage only once a native `CreateModel` or `AddField` fills it again, or a
|
|
614
|
+
followed rename moves storage under it, which is then probed under its name before the
|
|
615
|
+
plan; storage under a vacated name nothing native filled, such as a table a `RunSQL`
|
|
616
|
+
renamed there, cannot be proved empty and its removal is refused. Storage absent
|
|
617
|
+
before the plan is the plan's own only where a native creation of the plan adds it;
|
|
618
|
+
any other absent storage cannot be proved empty either. A table owned at the end of
|
|
619
|
+
the plan is not deleted, even by a declared drop, unless after the drop a native
|
|
620
|
+
creation, or a followed rename, puts storage under its name, as Django's removal and
|
|
621
|
+
addition of a many-to-many field with a new target does, and the owner did not own the
|
|
622
|
+
table when it was dropped: a model that comes to own the name after the drop owns that
|
|
623
|
+
new storage, but one that owned the table then owned the dropped rows. That identity
|
|
624
|
+
follows `RenameModel` only: a model that owned the table and moves to another app by
|
|
625
|
+
state-only operations after the drop, as Django documents for moving a model, is taken
|
|
626
|
+
for a new owner. A model that a state-only operation gives the name after the drop,
|
|
627
|
+
where nothing refilled the name, owns no table, and the drop stays refused. Under a
|
|
628
|
+
deleted model's own label, though, a model that did not own the table when it was
|
|
629
|
+
dropped is taken for that model created again, as histories commonly delete and create
|
|
630
|
+
a model again. So a model that state alone gives the deleted label's table is left
|
|
631
|
+
without one unnoticed, whichever operations do it: a state-only `CreateModel` or
|
|
632
|
+
`RenameModel` under that label, or a native creation or rename under another table
|
|
633
|
+
whose state a state-only operation then points at the deleted table. Where the dropped
|
|
634
|
+
table holds rows, the probe still refuses an undeclared drop.
|
|
635
|
+
- **Snapshot:** every proof is taken at `pre_migrate`, before the first operation.
|
|
636
|
+
Rows the plan itself writes, such as a `RunPython` that fills storage a later
|
|
637
|
+
operation of the plan drops, are not protected.
|
|
638
|
+
- **Refusal:** one `CommandError` names every refused migration, operation, model,
|
|
639
|
+
column or table and row count, shared tables included, and nothing is migrated, then
|
|
640
|
+
each remedy once. Removals that would destroy stored data, or delete a table another
|
|
641
|
+
model still owns, come under `unsafe migration drop`, and those the guard cannot judge
|
|
642
|
+
under `cannot prove migration drop safe`. The remedy for a shared table is to keep it
|
|
643
|
+
or change that owner first, since declaring the drop cannot help; authoring and
|
|
644
|
+
`retire_history --purge` refuse it in the same words. Shared storage whose identity
|
|
645
|
+
cannot be resolved needs a name that can be. A column no field of the state before
|
|
646
|
+
the plan is stored in needs the plan to start after the migration that gives it one:
|
|
647
|
+
where a native creation of the plan names that storage, the refusal names its
|
|
648
|
+
migration, as `migrate <app> <migration> --fake-initial` where that is an initial
|
|
649
|
+
migration, whose tables `--fake-initial` adopts, and native `migrate` can start after
|
|
650
|
+
it, and otherwise asks for the migration
|
|
651
|
+
that gives the storage its model. A plan that starts between the two halves of
|
|
652
|
+
Django's documented move of a model between apps, after the old app's state-only
|
|
653
|
+
deletion and before the new app's state-only creation, meets such columns too, and
|
|
654
|
+
the new app's creation is the migration to apply first. Where the walk went blind and
|
|
655
|
+
reads its state again after a migration, a removal it refuses from there on names
|
|
656
|
+
that migration: `migrate <app> <migration>` first, then `migrate`, judges the rest
|
|
657
|
+
afresh, its names followed again. Where the walk ended at an operation it cannot
|
|
658
|
+
copy, a removal it refuses from there on names that operation's migration the same
|
|
659
|
+
way, since native `migrate` copies no operation. Either is named only where native
|
|
660
|
+
`migrate` can start after it: copies of the operations that migration needs, the one
|
|
661
|
+
that cannot be copied stepped itself, applied to the state before the plan, render
|
|
662
|
+
afresh, as native `migrate` renders the state it starts from before it plans. Where
|
|
663
|
+
migrating there first would apply a migration whose removal the same refusal refuses,
|
|
664
|
+
the remedy says to resolve those removals first. `retire_history --purge` names the
|
|
665
|
+
rest of a retired label's chain to migrate first under the same check. Every
|
|
666
|
+
other refusal a stopped walk makes needs the history changed: a removal it cannot
|
|
667
|
+
read, ordered to come in a migration after the one where the state renders again; a
|
|
668
|
+
table drop whose owners at the end of the plan it cannot tell, ordered so that the
|
|
669
|
+
state renders there; and after the walk ends without that remedy, the operations of
|
|
670
|
+
the migration where it ended made ones that `copy.deepcopy` copies, or that Django's
|
|
671
|
+
migration state applies, or the removals ordered before it. Every remedy that names
|
|
672
|
+
`migrate` names `--database <alias>` where the alias migrated is not the default.
|
|
673
|
+
|
|
674
|
+
A migration declares a drop it intends with `IntendedRemoveField` or
|
|
675
|
+
`IntendedDeleteModel` from `django_compose.operations`: native subclasses applied and
|
|
676
|
+
serialized exactly like `RemoveField` and `DeleteModel`, so squashing keeps them.
|
|
677
|
+
Squashing folds a declared field removal into a following native `DeleteModel`, which
|
|
678
|
+
stays guarded. Only the declaring operation is exempt. A purge migration authored by
|
|
679
|
+
`retire_history --purge` declares nothing: purging retired data is a per-deployment
|
|
680
|
+
decision that `retire_history <label> --purge` applies, and a refusal names that
|
|
681
|
+
command.
|
|
682
|
+
|
|
683
|
+
Faked and backwards plans are not judged. `RunSQL` and other custom database code are
|
|
684
|
+
not parsed: a drop they make is not judged, and the walk follows no rename they make.
|
|
685
|
+
Beside the storage the probe refuses, under a vacated name or one absent before the
|
|
686
|
+
plan, storage they move under a name the walk accounts for is not detected: under a name
|
|
687
|
+
that held other storage before the plan, the guard probes that other storage, and under
|
|
688
|
+
one a native operation of the plan created or filled, it takes the storage for the
|
|
689
|
+
plan's own and probes nothing. That includes a `RunSQL` that swaps two tables present
|
|
690
|
+
before the plan. Two native drops predate the guard and are not judged:
|
|
691
|
+
`AlterOrderWithRespectTo` to `None` removes the `_order` column, and a model deletion
|
|
692
|
+
drops its implicit many-to-many tables unprobed, which can lose rows only when the field
|
|
693
|
+
sets `db_constraint=False`.
|
|
694
|
+
|
|
695
|
+
Native dispatch must resolve this package's `makemigrations` and `migrate`, or a
|
|
696
|
+
subclass of each. `ComposeConfig` is last in `INSTALLED_APPS`, so a same-named command
|
|
697
|
+
of any other app wins and would switch the guard off. System check
|
|
698
|
+
`django_compose.E002`, tagged `commands`, reports either. Before any database work,
|
|
699
|
+
`provision` refuses a shadowing `migrate`, which it runs, silenced or not, and refuses
|
|
700
|
+
whatever the `commands` checks report unless it is silenced, as its final system
|
|
701
|
+
check would only after migrating, with the provision record left `in_progress`. A
|
|
702
|
+
host that ships its own `makemigrations`, as django-linear-migrations does, keeps the
|
|
703
|
+
guard with a command that subclasses both, as `class Command(LinearCommand,
|
|
704
|
+
ComposeCommand)`: it keeps the guard's autodetector and passes both checks, with nothing
|
|
705
|
+
silenced. A host that silences `django_compose.E002` and Django's `commands.E001`
|
|
706
|
+
instead provisions as the system checks allow, but authors migrations without the
|
|
707
|
+
guard. The guard wraps the command's `execute`, so a subclass that replaces
|
|
708
|
+
`handle` keeps it; a subclass that overrides `execute` without calling it passes E002
|
|
709
|
+
but has no guard.
|
|
710
|
+
[Proposal 0005](proposals/0005-migrate-time-drop-guard.md) records these decisions.
|
|
711
|
+
|
|
498
712
|
## Database preparation and readiness
|
|
499
713
|
|
|
500
714
|
`django_compose.provision` owns database preparation for a startup-verified
|
|
@@ -23,11 +23,11 @@ The launcher exposes these Django management commands:
|
|
|
23
23
|
| Command | Purpose | Guide |
|
|
24
24
|
| --- | --- | --- |
|
|
25
25
|
| `compose` | Generate output; `--check` verifies output/history without writes; `--if-stale` skips a current build | [Lifecycle](SPEC.md#setup-lifecycle) |
|
|
26
|
-
| `makemigrations`, `migrate` | Author and apply ordinary Django migrations | [Migrations](migrations.md) |
|
|
26
|
+
| `makemigrations`, `migrate` | Author and apply ordinary Django migrations; the [drop guard](SPEC.md#drop-guard) refuses an autodetected drop of stored data, and at `migrate` a drop in the project's own history that would lose stored data or a table another model owns, or that it cannot prove safe | [Migrations](migrations.md) |
|
|
27
27
|
| `runserver` | Compose before Django's development-server reloads | [Development](configuration.md#serve-the-project) |
|
|
28
28
|
| `provision` | Apply migrations and app preparation hooks; `--check` verifies readiness | [Provisioning](provisioning.md) |
|
|
29
29
|
| `check_migrations` | Compare models/history; `--imports` audits retained Python dependencies | [History checks](migrations.md#disable-delete-or-uninstall) |
|
|
30
|
-
| `retire_history`, `reset_migration_history` | Explicit, guarded history maintenance | [
|
|
30
|
+
| `retire_history`, `reset_migration_history` | Explicit, guarded history maintenance | [History cutoffs](migrations.md#history-cutoffs) |
|
|
31
31
|
|
|
32
32
|
Build before serving; the serving process verifies output rather than rebuilding.
|
|
33
33
|
`DJANGO_COMPOSE_MODE` is `write`, `check`, or absent for serving. Use the launcher
|
|
@@ -103,8 +103,8 @@ in [`django_compose.declarations`](../src/django_compose/declarations.py) are:
|
|
|
103
103
|
`ModelDeclaration(attributes=..., meta_options=...)` using `DeclarationValue` values.
|
|
104
104
|
- `ArtifactHook` declares `external_root`, `phase` and `render(composition, models)`.
|
|
105
105
|
Models-phase hooks receive `ModelsView`; ready-phase hooks receive Django's registry.
|
|
106
|
-
- `MigrationPolicy.retired_primary_keys(model, alias)` supplies explicit
|
|
107
|
-
to
|
|
106
|
+
- `MigrationPolicy.retired_primary_keys(model, alias)` supplies explicit row
|
|
107
|
+
exemptions to the [drop guard](SPEC.md#drop-guard).
|
|
108
108
|
|
|
109
109
|
The supplied [`ModelComposition`](../src/django_compose/model_composition.py) exposes
|
|
110
110
|
ordered models, donors, parents and contributed fields; see [model contracts](SPEC.md#model-declarations).
|
|
@@ -138,5 +138,10 @@ project startup normally delegates verification to `configure`.
|
|
|
138
138
|
- `migrations.check_native_history(apps, *, labels)` compares effective native
|
|
139
139
|
state without database access; `migrations.history_labels()` reads retained
|
|
140
140
|
receipt labels. Projects author schema/data work through Django's native history.
|
|
141
|
+
- `operations.IntendedRemoveField` and `operations.IntendedDeleteModel` declare a
|
|
142
|
+
drop of stored data that a migration intends, such as after a `RunPython` move;
|
|
143
|
+
see [intended drops](migrations.md#declare-an-intended-drop).
|
|
144
|
+
`migrations.check_plan_drops(plan, *, using)` is the [drop guard](SPEC.md#drop-guard)
|
|
145
|
+
`migrate` runs from `pre_migrate`.
|
|
141
146
|
- The optional `django_compose.typing` mypy plugin analyzes composed models through
|
|
142
147
|
django-stubs. See [installation, configuration and limitations](dependencies.md#advanced-typing).
|
|
@@ -66,7 +66,7 @@ locates integration module files without importing them.
|
|
|
66
66
|
| --- | --- | --- |
|
|
67
67
|
| `ModelDeclarationHook` | `model_declaration(composition, source) -> ModelDeclaration` | Before rendering each generated model |
|
|
68
68
|
| `ArtifactHook` | `external_root: str`; `phase: Literal["models", "ready"]`; `render(composition, models) -> Mapping[Path, bytes]` | Models phase after concrete registration; ready phase in the final ready callback |
|
|
69
|
-
| `MigrationPolicy` | `retired_primary_keys(model, alias) -> Iterable[Any]` |
|
|
69
|
+
| `MigrationPolicy` | `retired_primary_keys(model, alias) -> Iterable[Any]` | The drop guard, in `makemigrations` and `migrate` |
|
|
70
70
|
|
|
71
71
|
A class can implement any combination. Duplicate integration classes, classes
|
|
72
72
|
that implement no protocol, and classes requiring constructor arguments fail.
|
|
@@ -87,8 +87,8 @@ Python package before migration commands or serving.
|
|
|
87
87
|
These are separate changes:
|
|
88
88
|
|
|
89
89
|
- **Delete a model from an enabled app:** Django detects the schema deletion,
|
|
90
|
-
even when the app now has no models module.
|
|
91
|
-
|
|
90
|
+
even when the app now has no models module. Its removal must pass the
|
|
91
|
+
[drop guard](#advanced-the-drop-guard-and-history-cutoffs).
|
|
92
92
|
- **Disable an app:** remove it from the project's selected apps and compose
|
|
93
93
|
again. Its retained migration history is represented by a history-only app
|
|
94
94
|
configuration, without loading its old models or lifecycle hooks. Disabling
|
|
@@ -142,8 +142,8 @@ Declare native dependencies so Django applies schema and data work in order.
|
|
|
142
142
|
A final-shaped schema does not prove that earlier data work ran.
|
|
143
143
|
|
|
144
144
|
Django owns `--check`, `--dry-run`, `--empty`, `--merge` and `--update`, migration
|
|
145
|
-
serialization and destinations. Authoring uses the
|
|
146
|
-
|
|
145
|
+
serialization and destinations. Authoring uses the drop guard and can read
|
|
146
|
+
eligible databases. Native command failure semantics apply;
|
|
147
147
|
there is no separate multi-phase authoring rollback journal. Authoring and compose
|
|
148
148
|
do not write migration recorder rows. `compose --check` compares native state
|
|
149
149
|
without querying a deployment database.
|
|
@@ -173,31 +173,66 @@ An explicit native `makemigrations --update` retains Django's deliberate rewrite
|
|
|
173
173
|
semantics; the former seal-based ban is gone. Audit retained imports before
|
|
174
174
|
removing providers, using `check_migrations --imports --removing`.
|
|
175
175
|
|
|
176
|
-
## Advanced:
|
|
177
|
-
|
|
178
|
-
The
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
`
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
with
|
|
200
|
-
|
|
176
|
+
## Advanced: the drop guard and history cutoffs
|
|
177
|
+
|
|
178
|
+
The [drop guard](SPEC.md#drop-guard) refuses a migration that would remove a column
|
|
179
|
+
or table still holding data, or delete a table another model still owns.
|
|
180
|
+
`makemigrations` applies it to what it autodetects; `migrate`, and therefore
|
|
181
|
+
`provision`, to the plan it is about to run, before any operation and also under
|
|
182
|
+
`--skip-checks`, judging only the history the project owns. The specification states
|
|
183
|
+
what it judges, on which databases, how it tells storage apart, and what it does not
|
|
184
|
+
judge.
|
|
185
|
+
|
|
186
|
+
A refusal names each migration, operation and the storage at stake with its remedy,
|
|
187
|
+
and nothing is migrated. Implement required data cutovers as reviewed migrations:
|
|
188
|
+
keep the storage, or move its data and [declare the drop](#declare-an-intended-drop).
|
|
189
|
+
Integrations exempt rows they retire with `MigrationPolicy`. Proving an unindexed
|
|
190
|
+
column empty scans its table.
|
|
191
|
+
|
|
192
|
+
On upgrade, a host whose unapplied history removes storage that still holds
|
|
193
|
+
data is refused at `migrate` and `provision` until each named removal is reviewed.
|
|
194
|
+
|
|
195
|
+
### Declare an intended drop
|
|
196
|
+
|
|
197
|
+
A migration may first move data elsewhere and then remove the old storage, which
|
|
198
|
+
still holds that data when `migrate` starts. Declare that drop by writing the
|
|
199
|
+
removal with `IntendedRemoveField` or `IntendedDeleteModel` from
|
|
200
|
+
`django_compose.operations` instead of the native operation:
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
from django.db import migrations
|
|
204
|
+
from django_compose.operations import IntendedRemoveField
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def move_prices(apps, schema_editor):
|
|
208
|
+
Item = apps.get_model("catalog", "Item")
|
|
209
|
+
Price = apps.get_model("catalog", "Price")
|
|
210
|
+
alias = schema_editor.connection.alias
|
|
211
|
+
Price._base_manager.using(alias).bulk_create(
|
|
212
|
+
Price(item_id=pk, amount=amount)
|
|
213
|
+
for pk, amount in Item._base_manager.using(alias).values_list("pk", "price")
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
class Migration(migrations.Migration):
|
|
218
|
+
dependencies = [("catalog", "0007_price")]
|
|
219
|
+
operations = [
|
|
220
|
+
migrations.RunPython(move_prices, migrations.RunPython.noop),
|
|
221
|
+
IntendedRemoveField(model_name="item", name="price"),
|
|
222
|
+
]
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
A declaration covers only its own operation; other removals in the same migration,
|
|
226
|
+
or the same storage removed by another migration, remain guarded. Operations that
|
|
227
|
+
drop no stored data, such as `RemoveConstraint`, stay native. A `RunPython` that
|
|
228
|
+
copies data may leave the source holding it: the declaration is what allows the drop.
|
|
229
|
+
The import becomes part of retained history; the module imports only Django.
|
|
230
|
+
|
|
231
|
+
`makemigrations` keeps refusing to autodetect a drop while an eligible database still
|
|
232
|
+
holds the data. Author the cutover migration first, for example from
|
|
233
|
+
`makemigrations --empty`, so the models and history agree.
|
|
234
|
+
|
|
235
|
+
### History cutoffs
|
|
201
236
|
|
|
202
237
|
`retire_history <label>` is an explicit cutoff for a history-only app. It requires
|
|
203
238
|
consistent, fully applied history across the configured databases selected by
|
|
@@ -213,10 +248,12 @@ Its optional `--purge` authors and applies a final native deletion migration
|
|
|
213
248
|
across the same database scope before retirement. It refuses deletion of tables
|
|
214
249
|
still owned by active models before authoring or applying changes. A failed
|
|
215
250
|
application retains that migration for retry and does not mark retirement
|
|
216
|
-
complete.
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
251
|
+
complete. The purge is the explicit decision to drop that data, applied on each
|
|
252
|
+
deployment with `retire_history <label> --purge`; the [drop guard](SPEC.md#drop-guard)
|
|
253
|
+
states how `migrate` treats a pending purge migration. Successful
|
|
254
|
+
retirement updates the build record under the normal writer lock; the next
|
|
255
|
+
compose removes the history-only configuration. Removing the retired migration
|
|
256
|
+
package from version control is a separate coordinated cutoff decision.
|
|
220
257
|
|
|
221
258
|
`reset_migration_history` replaces an explicitly selected, fully applied,
|
|
222
259
|
model-clean history with fresh initial migrations. It refuses unsafe cross-app
|