summary refs log tree commit diff
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2015-03-02 11:39:58 +0000
committerKegan Dougal <kegan@matrix.org>2015-03-02 11:39:58 +0000
commit3f6b36d96e7e718ff7fb9d98a8211448f6b0d7e9 (patch)
treeb39f49d4d0daf5d799f061bb65a48bf1623f6be2
parentImplement exclusive namespace checks. (diff)
downloadsynapse-3f6b36d96e7e718ff7fb9d98a8211448f6b0d7e9.tar.xz
Add upgrade script
-rw-r--r--scripts/upgrade_appservice_db.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/scripts/upgrade_appservice_db.py b/scripts/upgrade_appservice_db.py
new file mode 100644
index 0000000000..acdee56d9f
--- /dev/null
+++ b/scripts/upgrade_appservice_db.py
@@ -0,0 +1,36 @@
+import argparse
+import json
+import sqlite3
+
+
+def main(dbname):
+    con = sqlite3.connect(dbname)
+    cur = con.cursor()
+    cur.execute("SELECT id, regex FROM application_services_regex")
+    for row in cur.fetchall():
+        try:
+            print "checking %s..." % row[0]
+            json.loads(row[1])
+            print "Already in new format"
+        except ValueError:
+            # row isn't in json, make it so.
+            string_regex = row[1]
+            new_regex = json.dumps({
+                "regex": string_regex,
+                "exclusive": True
+            })
+            cur.execute(
+                "UPDATE application_services_regex SET regex=? WHERE id=?",
+                (new_regex, row[0])
+            )
+    cur.close()
+    con.commit()
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser()
+
+    parser.add_argument("database")
+    args = parser.parse_args()
+
+    main(args.database)