summaryrefslogtreecommitdiffstats
path: root/scripts/daily_cleanup.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/daily_cleanup.py')
-rw-r--r--scripts/daily_cleanup.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/scripts/daily_cleanup.py b/scripts/daily_cleanup.py
new file mode 100644
index 0000000..98f997b
--- /dev/null
+++ b/scripts/daily_cleanup.py
@@ -0,0 +1,14 @@
+from django.db import backend, connection, transaction
+""" Daily cleanup file
+ This purges the session data that is old from the session table.
+"""
+def clean_up():
+ # Clean up old database records
+ cursor = connection.cursor()
+ cursor.execute("DELETE FROM %s WHERE %s < NOW()" % \
+ (backend.quote_name('django_session'), backend.quote_name('expire_date')))
+ cursor.execute("OPTIMIZE TABLE %s" % backend.quote_name('django_session'))
+ transaction.commit_unless_managed()
+
+if __name__ == "__main__":
+ clean_up()