From dd3d72d8d379dc1faedf45a086afe5f0719008dc Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 20 Nov 2019 11:53:35 +0000 Subject: [PATCH] add migration script for old aliases --- migration/v01.16.00-aliases.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 migration/v01.16.00-aliases.py diff --git a/migration/v01.16.00-aliases.py b/migration/v01.16.00-aliases.py new file mode 100644 index 00000000..ec0dd2cc --- /dev/null +++ b/migration/v01.16.00-aliases.py @@ -0,0 +1,26 @@ +# Used to migrate aliases from prior to v1.16.0 +# usage: $ python3 migration/v01.16.00-aliases.py ~/.bitbot/bot.db + +import argparse +parser = argparse.ArgumentParser(description="Migrate pre-v1.16.0 aliases") +parser.add_argument("database") +args = parser.parse_args() + +import json, sqlite3 +database = sqlite3.connect(args.database) + +cursor = database.cursor() +cursor.execute( + """SELECT server_id, value FROM server_settings + WHERE setting='command-aliases'""") +results = cursor.fetchall() +print(results) + +for server_id, value in results: + aliases = json.loads(value) + for alias, command in aliases.items(): + print(server_id, alias, command) + cursor.execute("INSERT INTO server_settings VALUES (?, ?, ?)", + [server_id, "alias-%s" % alias, json.dumps(command)]) +database.commit() +database.close()