Run deltas and bump user_version in upgrade script

pull/93/head
Kegan Dougal 2015-03-02 13:38:57 +00:00
parent 3f6b36d96e
commit c3c01641d2
3 changed files with 29 additions and 6 deletions

View File

@ -12,6 +12,11 @@ Servers which use captchas will need to add their public key to::
This is required in order to support registration fallback (typically used on
mobile devices).
Servers which have registered application services need to upgrade their
database as the format of stored application services has changed in Synapse.
Run ``python upgrade_appservice_db.py <database file path>`` to convert to the
new format.
Upgrading to v0.7.0
===================

View File

@ -1,17 +1,28 @@
from synapse.storage import read_schema
import argparse
import json
import sqlite3
def main(dbname):
con = sqlite3.connect(dbname)
cur = con.cursor()
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])
print "Already in new format"
except ValueError:
# row isn't in json, make it so.
string_regex = row[1]
@ -23,13 +34,20 @@ def main(dbname):
"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()

View File

@ -74,7 +74,7 @@ SCHEMAS = [
# Remember to update this number every time an incompatible change is made to
# database schema files, so the users will be informed on server restarts.
SCHEMA_VERSION = 13
SCHEMA_VERSION = 14
dir_path = os.path.abspath(os.path.dirname(__file__))