Fix bug FS#8417
[archweb_dev-nj.git] / scripts / daily_cleanup.py
blob98f997bff711c33cfbcabda20e34e5d82df647e0
1 from django.db import backend, connection, transaction
2 """ Daily cleanup file
3 This purges the session data that is old from the session table.
4 """
5 def clean_up():
6 # Clean up old database records
7 cursor = connection.cursor()
8 cursor.execute("DELETE FROM %s WHERE %s < NOW()" % \
9 (backend.quote_name('django_session'), backend.quote_name('expire_date')))
10 cursor.execute("OPTIMIZE TABLE %s" % backend.quote_name('django_session'))
11 transaction.commit_unless_managed()
13 if __name__ == "__main__":
14 clean_up()