]> git.openstreetmap.org Git - osqa.git/blobdiff - forum_modules/pgfulltext/startup.py
Jira OSQA-712, migrating to the new Databases setting format
[osqa.git] / forum_modules / pgfulltext / startup.py
index 6a6f85d1791850587a44ed070c34d66568fb68d5..59990b5e4162e2932c8c0a4f1e277e4ace7fd300 100644 (file)
@@ -1,40 +1,27 @@
-import os\r
-from forum.models import KeyValue\r
-from django.db import connection, transaction\r
-\r
-KEY = 'PG_FTSTRIGGERS_VERSION'\r
-VERSION = 3\r
-install = False\r
-\r
-try:\r
-    version = KeyValue.objects.get(key=KEY).value\r
-    if version < VERSION:\r
-        install = True\r
-except:\r
-    install = True\r
-\r
-\r
-if install:\r
-    f = open(os.path.join(os.path.dirname(__file__), 'pg_fts_install.sql'), 'r')\r
-\r
-    try:\r
-        cursor = connection.cursor()\r
-        cursor.execute(f.read())\r
-        transaction.commit_unless_managed()\r
-\r
-        try:\r
-            kv = KeyValue.objects.get(key=KEY)\r
-        except:\r
-            kv = KeyValue(key=KEY)\r
-\r
-        kv.value = VERSION\r
-        kv.save()\r
-        \r
-    except Exception, e:\r
-        #import sys, traceback\r
-        #traceback.print_exc(file=sys.stdout)\r
-        pass\r
-    finally:\r
-        cursor.close()\r
-\r
-    f.close()\r
+import os
+from forum.models import KeyValue
+from django.db import connection, transaction
+import settings
+
+VERSION = 11
+
+if int(settings.PG_FTSTRIGGERS_VERSION) < VERSION:
+    f = open(os.path.join(os.path.dirname(__file__), 'pg_fts_install.sql'), 'r')
+
+    try:
+        cursor = connection.cursor()
+        cursor.execute(f.read())
+        transaction.commit_unless_managed()
+
+        settings.PG_FTSTRIGGERS_VERSION.set_value(VERSION)
+        
+    except Exception, e:
+        #import sys, traceback
+        #traceback.print_exc(file=sys.stdout)
+        pass
+    finally:
+        cursor.close()
+
+    f.close()
+
+import handlers