|
|
@ -1,17 +1,28 @@ |
|
|
|
|
|
|
|
from synapse.storage import read_schema |
|
|
|
import argparse |
|
|
|
import argparse |
|
|
|
import json |
|
|
|
import json |
|
|
|
import sqlite3 |
|
|
|
import sqlite3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(dbname): |
|
|
|
def do_other_deltas(cursor): |
|
|
|
con = sqlite3.connect(dbname) |
|
|
|
cursor.execute("PRAGMA user_version") |
|
|
|
cur = con.cursor() |
|
|
|
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") |
|
|
|
cur.execute("SELECT id, regex FROM application_services_regex") |
|
|
|
for row in cur.fetchall(): |
|
|
|
for row in cur.fetchall(): |
|
|
|
try: |
|
|
|
try: |
|
|
|
print "checking %s..." % row[0] |
|
|
|
print "checking %s..." % row[0] |
|
|
|
json.loads(row[1]) |
|
|
|
json.loads(row[1]) |
|
|
|
print "Already in new format" |
|
|
|
|
|
|
|
except ValueError: |
|
|
|
except ValueError: |
|
|
|
# row isn't in json, make it so. |
|
|
|
# row isn't in json, make it so. |
|
|
|
string_regex = row[1] |
|
|
|
string_regex = row[1] |
|
|
@ -23,13 +34,20 @@ def main(dbname): |
|
|
|
"UPDATE application_services_regex SET regex=? WHERE id=?", |
|
|
|
"UPDATE application_services_regex SET regex=? WHERE id=?", |
|
|
|
(new_regex, row[0]) |
|
|
|
(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() |
|
|
|
cur.close() |
|
|
|
con.commit() |
|
|
|
con.commit() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
if __name__ == "__main__": |
|
|
|
parser = argparse.ArgumentParser() |
|
|
|
parser = argparse.ArgumentParser() |
|
|
|
|
|
|
|
|
|
|
|
parser.add_argument("database") |
|
|
|
parser.add_argument("database") |
|
|
|
args = parser.parse_args() |
|
|
|
args = parser.parse_args() |
|
|
|
|
|
|
|
|
|
|
|