mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Add upgrade script
This commit is contained in:
parent
58ff066064
commit
3f6b36d96e
36
scripts/upgrade_appservice_db.py
Normal file
36
scripts/upgrade_appservice_db.py
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user