diff --git a/harambot/database/migrations.py b/harambot/database/migrations.py index 22a4253..dbbd5cf 100644 --- a/harambot/database/migrations.py +++ b/harambot/database/migrations.py @@ -1,3 +1,5 @@ +import logging + from playhouse.migrate import SqliteMigrator, MySQLMigrator, PostgresqlMigrator from playhouse.migrate import migrate from playhouse.dataset import DataSet @@ -9,6 +11,10 @@ from harambot.config import settings +logger = logging.getLogger("discord") +logger.setLevel(settings.LOGLEVEL) + + if "DATABASE_URL" in settings: database = connect(settings.database_url) else: @@ -43,22 +49,28 @@ def beta040_migrations(): dataSet = DataSet(":memory:") guilds = dataSet["guild"] for guild in guilds.all(): - print(guild["id"]) - dataSet.query( - sql="UPDATE guild SET access_token = ? WHERE id = ?", - params=[ - f.encrypt(guild["access_token"].encode()).decode(), - guild["id"], - ], + logger.info( + "Encrypted token: " + + "'{}'".format(f.encrypt(guild["access_token"].encode()).decode()) ) - dataSet.query( - sql="UPDATE guild SET refresh_token = ? WHERE id = ?", - params=[ - f.encrypt(guild["refresh_token"].encode()).decode(), - guild["id"], - ], - ) - + logger.info("Guild ID:") + logger.info(guild["id"]) + with dataSet.transaction() as txn: + guilds.update( + id=guild["id"], + access_token=f.encrypt( + guild["access_token"].encode() + ).decode(), + columns=["id"], + ) + guilds.update( + id=guild["id"], + refresh_token=f.encrypt( + guild["refresh_token"].encode() + ).decode(), + columns=["id"], + ) + txn.commit() # Add new fields for transaction polling transaction_polling_service_enabled = IntegerField(default=0) transaction_polling_webhook = TextField(null=True) diff --git a/pyproject.toml b/pyproject.toml index 24fcf6f..06a2bbb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "harambot" -version = "0.4.0" +version = "0.4.0.post1" description = "A Yahoo Fantasy Sports bot for Discord" authors = ["DMcP89 "] license = "MIT"