Opened 12 years ago

Closed 12 years ago

Last modified 10 years ago

#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: UI/UX:


We should automate the checking of whether everything is properly installed in the database for a particular app. For instance, a command such as 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 Changed 12 years ago by Moof <moof@…>

Cc: moof@… added

One possible extentiosn of what you could do knowing this information is up over here:

comment:2 Changed 12 years ago by anonymous

Component: Core frameworkDatabase wrapper

comment:3 Changed 12 years ago by anonymous

Component: Database wrapperCore framework

comment:4 Changed 12 years ago by mrtact@…

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 Changed 12 years ago by Brendan O'Connor <brenocon@…>

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 Changed 12 years ago by brantley (deadwisdom@…

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 Changed 12 years ago by Adrian Holovaty

Component: Core frameworkMetasystem

comment:8 Changed 12 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

The new syncdb command accomplishes this. (Minus the database-schema changes, of course, but that's another ticket.)

comment:9 Changed 11 years ago by URL

Type: enhancement
Note: See TracTickets for help on using tickets.
Back to Top