Login

Snippets by kahless

Snippet List

Simple solution for model schema evolution / database changelog

This is a very simple approach to "schema evolution" (Not sure if you can even call it so) - I use it for my project: [SCT](http://sct.sphene.net) and it seems to work quite nicely. The idea is, that if you add or change your models, you add a 'changelog' attribute to your class which defines the SQL queries required to update your models. Of course this only works for one database type... An example 'syncdb' call if a new changelog entry was detected: kahless@localhost ~/dev/python-new/sphenecommunity/sphenecommunity $ ./manage.py syncdb Executing module body. 2007-06-16 00: SQL Statement: ALTER TABLE "sphboard_post" ADD markup varchar(250) NULL Detected changes - Do you want to execute SQL Statements ? (yes,no): So if the SQL statement won't work with the database the user is currently running, he at least knows exactly what he is expected to change in his models. and he can stop automatic execution by simply entering 'no' here.

  • changelog
  • schema-evolution
Read More

kahless has posted 2 snippets.