Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Model updates in early development stages [RSS Feed]

#1 Nov. 23, 2005 18:34:52

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Model updates in early development stages


There is a thread in django-developers list talking about the way Djangoand Rails handle frequent changes to models on early stages ofdevelopment ('prototyping' - to sound cool). Neither framwork does thistransparently which is understandable because it's definitely hard andeven arguably desirable at all :-).I'd like to share my method of doing this task where I use oneundocumented feature that Adrian Holovaty once mentioned in this list.I'm writing here because I'm not sure if it's ready for the Cookbook inthe wiki. May be everyone will reply that I'm doing it incrediblypainful way and should just read this URL and that URL to do it right:-). Also feel free to correct my English since it's not my nativelanguage. So to the point.1. I begin designing a model to the whole depths of my current domainknowledge. But I'm absolutely sure that in a near future my knowledgewill change and will require changing models.2. Significant changes to models that require database changes are:adding/removing/renaming fields, adding/removing/renaming tables,changing types and sizes of fields. But there is no point of doingsomething with database when adding some custom method or changing METAclass.3. When database change is required I use:

django-admin.py sqlreset <appname>... which effectvely wipes out entire application structure then createsnew one.4. But this also wipes all the test data in your database and if you hadto recreate it by hand each time it would defeat the whole point of thismethod :-). Luckily you can easily automate it. After creating thestructure 'sqlreset' tries to locate and execute SQL script in<projectdir>/apps/<appname>/sql/<appname>.sqlThis script should contain SQL statements that create test data for yourapplication.Creating this file from scratch by hand is boring. Instead I create allthe data using shiny Django's admin interface and then use databasetools to generate such script. For PostgreSQL this utility calledpg_dump and can be used like this:pg_dump -a -D <db_name> > <appname>.sql

Options mean:-a: dump only data, not structure (because structure will be created bysqlreset)-D: use INSERT statements with column namesThen I edit the resulting file removing all core data leaving onlyINSERTS into my applications tables.It still sounds a bit complex but I've done it only first time. On allsubsequent changes it's easier to correct this file by hand. And oftenit's not even required when you, for example, just change the length ofa text field.6. The 'sqlreset' outputs all SQL statements to console. To furtherautomate the task I redirect this output into command-line databaseclient instead of copy-pasting it by hand:django-admin.py sqlreset <appname> | psql <db_name>

Offline

  • Root
  • » Django
  • » Model updates in early development stages [RSS Feed]

Board footer

Moderator control

Enjoy the 20th of January
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support