summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorDavid Baker <dave@matrix.org>2015-03-04 14:56:41 +0000
committerDavid Baker <dave@matrix.org>2015-03-04 14:56:41 +0000
commit92b3dc3219ccabc6997c66197a3b879dc49f5597 (patch)
tree083acae90fadadf500918d58754a628feff86351 /scripts
parentUse if not results rather than len, as per feedback. (diff)
parentFix upgrade instructions (diff)
downloadsynapse-92b3dc3219ccabc6997c66197a3b879dc49f5597.tar.xz
Merge branch 'develop' into pushrules2
Diffstat (limited to 'scripts')
-rw-r--r--scripts/upgrade_appservice_db.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/scripts/upgrade_appservice_db.py b/scripts/upgrade_appservice_db.py
new file mode 100644
index 0000000000..ae1b91c64f
--- /dev/null
+++ b/scripts/upgrade_appservice_db.py
@@ -0,0 +1,54 @@
+from synapse.storage import read_schema
+import argparse
+import json
+import sqlite3
+
+
+def do_other_deltas(cursor):
+    cursor.execute("PRAGMA user_version")
+    row = cursor.fetchone()
+
+    if row and row[0]:
+        user_version = row[0]
+        # Run every version since after the current version.
+        for v in range(user_version + 1, 10):
+            print "Running delta: %d" % (v,)
+            sql_script = read_schema("delta/v%d" % (v,))
+            cursor.executescript(sql_script)
+
+
+def update_app_service_table(cur):
+    cur.execute("SELECT id, regex FROM application_services_regex")
+    for row in cur.fetchall():
+        try:
+            print "checking %s..." % row[0]
+            json.loads(row[1])
+        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])
+            )
+
+
+def main(dbname):
+    con = sqlite3.connect(dbname)
+    cur = con.cursor()
+    do_other_deltas(cur)
+    update_app_service_table(cur)
+    cur.execute("PRAGMA user_version = 14")
+    cur.close()
+    con.commit()
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser()
+    parser.add_argument("database")
+    args = parser.parse_args()
+
+    main(args.database)