Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Model updates in early development stages
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Maniac  
View profile  
 More options Nov 23 2005, 12:12 pm
From: Maniac <Man...@SoftwareManiacs.Org>
Date: Wed, 23 Nov 2005 20:12:47 +0300
Local: Wed, Nov 23 2005 12:12 pm
Subject: Model updates in early development stages
There is a thread in django-developers list talking about the way Django
and Rails handle frequent changes to models on early stages of
development ('prototyping' - to sound cool). Neither framwork does this
transparently which is understandable because it's definitely hard and
even arguably desirable at all :-).

I'd like to share my method of doing this task where I use one
undocumented 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 in
the wiki. May be everyone will reply that I'm doing it incredibly
painful 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 native
language. So to the point.

1. I begin designing a model to the whole depths of my current domain
knowledge. But I'm absolutely sure that in a near future my knowledge
will 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 doing
something with database when adding some custom method or changing META
class.

3. When database change is required I use:

    django-admin.py sqlreset <appname>

... which effectvely wipes out entire application structure then creates
new one.

4. But this also wipes all the test data in your database and if you had
to recreate it by hand each time it would defeat the whole point of this
method :-). Luckily you can easily automate it. After creating the
structure 'sqlreset' tries to locate and execute SQL script in

    <projectdir>/apps/<appname>/sql/<appname>.sql

This script should contain SQL statements that create test data for your
application.

Creating this file from scratch by hand is boring. Instead I create all
the data using shiny Django's admin interface and then use database
tools to generate such script. For PostgreSQL this utility called
pg_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 by
sqlreset)
-D: use INSERT statements with column names

Then I edit the resulting file removing all core data leaving only
INSERTS into my applications tables.

It still sounds a bit complex but I've done it only first time. On all
subsequent changes it's easier to correct this file by hand. And often
it's not even required when you, for example, just change the length of
a text field.

6. The 'sqlreset' outputs all SQL statements to console. To further
automate the task I redirect this output into command-line database
client instead of copy-pasting it by hand:

    django-admin.py sqlreset <appname> | psql <db_name>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »