From 3e84fda56929c90dce1e30df70092344cd3a1663 Mon Sep 17 00:00:00 2001 From: Danny de Jong Date: Mon, 23 Sep 2024 09:24:10 +0200 Subject: [PATCH] [IMP] Improved the database defusion code --- bin/migrate.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/bin/migrate.py b/bin/migrate.py index bf13440..6e9204b 100755 --- a/bin/migrate.py +++ b/bin/migrate.py @@ -242,13 +242,23 @@ def cmd_system(command): def disable_dangerous_stuff(): + queries = [ + ("UPDATE ir_mail_server SET active = FALSE, smtp_host = 'f'", True), + ("UPDATE fetchmail_server SETE active = FALSE", False), + ("UPDATE ir_cron SET active = FALSE", True), + ] dbname = os.environ["PGDATABASE"] - cmd("psql -d %s -c 'UPDATE ir_mail_server SET active = FALSE'" % dbname) - try: - cmd("psql -d %s -c 'UPDATE fetchmail_server SET active = FALSE'" % dbname) - except: - pass - cmd("psql -d %s -c 'UPDATE ir_cron SET active = FALSE'" % dbname) + + with psycopg.connect("dbname=" + os.environ["PGDATABASE"]) as conn: + with conn.cursor() as cur: + for query, required in queries: + try: + cur.execute(query) + except Exception as e: + if required: + logging.error("Unable to defuse database, the following query failed:") + logging.error(query) + raise e def find_db_version_from_progress():