#12 closed (fixed)
Add metasystem database-check functionality
Reported by: | Adrian Holovaty | Owned by: | Adrian Holovaty |
---|---|---|---|
Component: | Metasystem | Version: | |
Severity: | normal | Keywords: | |
Cc: | moof@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
We should automate the checking of whether everything is properly installed in the database for a particular app. For instance, a command such as django-admin.py dbcheck news
would:
- Check that the package exists in the DB.
- Check that all the permissions exist in the DB.
- Check that there aren't any *extra* permissions in the DB that the model doesn't know about.
- Check that all the content types exist in the DB.
- Check that there aren't any *extra* content types in the DB for this app.
- Check that there aren't any missing fields.
- Check that the fields are in the correct data type.
Change History (9)
comment:1 by , 19 years ago
Cc: | added |
---|
comment:2 by , 19 years ago
Component: | Core framework → Database wrapper |
---|
comment:3 by , 19 years ago
Component: | Database wrapper → Core framework |
---|
comment:4 by , 19 years ago
I have an even easier suggestion.
Add a table to the defaults created by django-admin init. Each row of the table corresponds to one model file. This table has two fields: hash and text. When an app is installed, take the full text of each model file and put it in the text field. Hash the text and put it in the hash field. When you run a db-check (which should be automatic at server startup, imho), simply hash each current model file and compare it to the hash stored in the db for that model file. If they differ, the model has changed.
At that point, fetch the full text of the model file from the db and diff it against current. It should be fairly easy to tie lines that differ to particular data structure. This provides you with a comprehensive set of what has changed.
- Tim Keating
comment:5 by , 19 years ago
Excellent idea! After doing the diff, the next step would be to generate ALTER TABLE statements if possible (if the schemas aren't very different...)
comment:6 by , 19 years ago
I have created a way to update your database dependant on an updated model. I created a django-developers posting that goes into greater detail.
comment:7 by , 19 years ago
Component: | Core framework → Metasystem |
---|
comment:8 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
The new syncdb
command accomplishes this. (Minus the database-schema changes, of course, but that's another ticket.)
comment:9 by , 18 years ago
Type: | enhancement |
---|
One possible extentiosn of what you could do knowing this information is up over here: http://metamoof.net/blog/2005/07/26/well_i%27ll_be_django%27d