Add mechanism for controlling which models are synchronized onto which database in multidb
|Reported by:||russellm||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.1|
|Cc:||Triage Stage:||Design decision needed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
At present synchronizing multiple databases where you *dont* want certain models on certain databases is a little fiddly. If you want to exclude an entire app, you can use --exclude on syncdb, but if you just want to disable a a single model, you can't - you need to manually roll out your synchronization. There is also a problem during testing, since that can't be manually implemented.
The usual suggestion here is an entry in settings.py, which would be exceedingly verbose and for the simple case, and worse for the complex case.
However, a programmatic approach leveraging the new Database Router should work. We could add an 'allow_syncdb(using, model)' interface to syncdb; this gets interrogated by syncdb (and other places that need it) to determine if a model should be visible on the given alias. Default behaviour is "yes"; the method can return True/False/None in the same way that allow_relation does right now.
This would allow us to remove --exclude options from loaddata and syncdb, allows for test syncdb calls to be more specific, and would allow syncdb under normal operation to be completely automated.
Change History (5)
Changed 5 years ago by russellm
comment:1 Changed 5 years ago by russellm
- Needs documentation unset
- Needs tests unset
- Patch needs improvement set
- Triage Stage changed from Unreviewed to Design decision needed