> I only want to keep 6 months worth of data. How can I
 > efficiently delete a month and all it's associated
 > services and those services associated pages? (in this
 > app, there could be about 3 million pages that are
 > associated with each month though a bunch of service
 > objects)

I wouldn't try to do it from within the web app itself --
I'd schedule some wee-hours cron job to do the deletion.  If
your DB has referential integrity and these are set up as
cascading deletes, you can just delete from Month and the
Service and Page items will go with it automatically.  The
other trick is knowing which months fall off the edge of the
6mo boundary.  Your Month is defined as a string, and I
don't see any actual date information in it.  Having actual
dates instead of month-names would make this a lot easier.

In all, I'd just skip Django completely and do something
like create a quick shell-script to execute the raw SQL and 
schedule it to run monthly

###############################
   #!/bin/sh
   psql << EOF
    DELETE FROM Month
    WHERE
     monthname = to_char(
        current_date -
        interval '6 months',
        'MONTH')
     or monthname = to_char(
        current_date -
        interval '7 months',
        'MONTH')
     or monthname = to_char(
        current_date -
        interval '8 months',
        'MONTH')
     or monthname = to_char(
        current_date -
        interval '9 months',
        'MONTH')
     or monthname = to_char(
        current_date -
        interval '10 months',
        'MONTH')
     or monthname = to_char(
        current_date -
        interval '11 months',
        'MONTH')
     or monthname = to_char(
        current_date -
        interval '12 months',
        'MONTH')

   EOF

###############################

If you had actual date fields, it would be as simple as

   DELETE FROM Month
   WHERE datefield < current_date - INTERVAL '6 months'

(date arithmetic/extraction functions vary from db to db...the 
above should be fairly close to postgres syntax)

-tim






--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to