On Fri, Apr 12, 2013 at 8:00 PM, Joey Espinosa <jlouis.espin...@gmail.com> wrote: > > Hey guys, > > I have a situation where I have test data that has been entered into a > demo database (MySQL). During the demo of the app with a customer, data will > be altered. After the demo is complete, I need to "reset" the demo data back > to what it was before the demo. > > I realize I could do this easily by dumping the database and then > restoring it after the demo is complete, but there's a catch... the dates > all need to change, too. > > So, say the demo happens on 05/01. I have an "Event" object with a date of > "05/22" (21 days in the future). When the demo gets reset (I'm planning on a > nightly reset, maybe 2am or something), it needs to change ALL the dates in > the database to have the same "timedelta" to the next day. So on the next > day, 05/02, that same "Event" object would have a date of "05/23" (still 21 > days in the future). This is necessary to keep things like date-based > notifications, triggers, and other related things always in the same state > whenever the demo occurs. > > I figure the steps would go something like this: > 1) Dump database > 2) // do demo > 3) Restore database from dump > 4) Some sort of django management command run on a cronjob to change all > dates (or maybe straight SQL in a PROCEDURE or something). > > Any ideas on how to accomplish this?
Use traditional fixtures for any objects that are not date dependant. https://docs.djangoproject.com/en/1.5/howto/initial-data/#providing-initial-data-with-fixtures Use SQL fixtures for any objects that are date dependant, and specify the date field in terms of "NOW() + INTERVAL 21 DAY" or similar. https://docs.djangoproject.com/en/1.5/howto/initial-data/#providing-initial-sql-data You can use the dumpdata command to create traditional fixtures, the SQL ones you will need to craft by hand. Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.